Multiple HTTP request - Rails
Posted
by bradleyg
on Stack Overflow
See other posts from Stack Overflow
or by bradleyg
Published on 2010-05-19T13:55:45Z
Indexed on
2010/05/19
14:00 UTC
Read the original article
Hit count: 162
My application checks a number of domains to see if they are valid (approx 100). I have the following code to check a single domain:
def self.test_url uri, limit = 10
if limit == 0
return get_error_messages("001")
end
begin
url = URI.parse(uri)
response = Net::HTTP.start(url.host, url.port).request_head('/')
rescue SocketError => e
return get_error_messages("002")
end
case response
when Net::HTTPRedirection then test_url(response['location'], limit - 1)
else return get_error_messages(response.code)
end
end
The code checks for the response code while taking into account redirects. This works fine. The only problem I have is when I put this in a loop I want it to run in parallel. So I don't have to wait for domain 1 to respond before I can request domain 2.
I have managed this in PHP using curl_multi to run the requests in parallel. Is there a similar thing I can do in Rails?
© Stack Overflow or respective owner