|
|
| No such thing as a small change | |
| PerlMonks |
Re: Get Timout with LWPby tachyon (Chancellor) |
| on Jun 21, 2004 at 00:43 UTC ( #368344=note: print w/ replies, xml ) | Need Help?? |
|
LWP::Simple is just that. Simple. It will hang if it can open a socket to a server but the server then plays dead and does not respond. LWP::UserAgent is much more sophisticated with its timeouts and will return if it times out....... BUT THERE IS A CAVEAT: Because of the way it is implemented in LWP::UserAgent the timeout is best termed as *fuzzy*. It will timeout but if you have a connection to a (say) overloaded server that trickle feeds data back to your client application it may take orders of magnitude longer to timeout than the number you specify. If you absolutely need a hard limit use alarm. Here is an example. Although the timeout is set to 2 seconds LWP will wait 30 seconds to get the trickle data. Effectively what the timeout means to LWP is 1) make the connection within TIMEOUT seconds and 2) get at least one byte of data from a non blocking socket every TIMEOUT seconds. It will return if either of these are not fulfilled but as you can see you can still kinda hang it. As an aside it you are scraping sites, and they run anti-scraping response throttling this scenario if quite realistic.
cheers tachyon
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||