Ive built a form on a webpage that allows a user to enter a URL and some information about the URL's CSS is returned. The tool works fine, apart from one issue i have noticed.
When i enter the URL of the site where the script is hosted (tested locally, on a staging server and on a production server), the open-uri command 'open' returns a Timeout::Error. Now this isn't hugely surprising, i'm guessing something is getting locked up somewhere along the line and in the process of running the script and opening the current URL, processes are getting tied up a little.
For reference, here is the method where the Timeout occurs:
# loads the Nokogiri XML object if it hasn't already been loaded
def site
begin
timeout(10) do
@site ||= Nokogiri::HTML(open(url))
end
rescue Timeout::Error
return nil
end
end
My question is,开发者_运维百科 how do i enable the script to be able to 'open' the domain the script is currently running on? Do i need to create another Thread or something to process this particular aspect of my tool, if so how do i ensure the rest of my script isn't run until i receive something valid from the 'open' command?
Thanks for any suggestions or tips on this.
I wonder if you're getting into a recursive loop. Are you seeing repeated entries in your httpd log showing requests for the same site?
If so you might want to short-circuit requests to that particular domain and pre-stuff the @site
instance variable so it falls through.
精彩评论