From the beginning of the coding, I was intent on using LWP to get the pages, but I ran into a bit of an issue. Though LWP does have a lot of functionality, I wansn't using most of it, and I ended up wasting a lot of CPU cycles waiting for LWP overhead.
So, I changed over to using HTTP::Lite. Speed improved greatly, cutting processing and waiting times almost in half. This is a good thing, since the project required the polling of multiple pages to occur simultaneously. It's an on-demand world and I have an on-demand-er client.
HTTP::Lite lacks one small bit of functionality that I needed, though. A way to check for a timeout. What to do? Do I muddle through without it, and have some occasions with 15-20 second waits for a page? Or do I go back to using the slower, but more reliable LWP?
Answer: Neither.
The timeout factor for page loading is something that I was already considering in my code, and was contained in a variable. Since I could pass that to LWP, why not use it in another way for HTTP::Lite.
Here is the HTTP::Lite with a timeout :
Usual caveats apply here, such as declaring variables and 'use' statements. Bonus here is that with adding the sleep(.1), the code acutally runs faster.sub HTTP_Request { (undef, $timeout, $url) = @_; $http = new HTTP::Lite; $st = time(); until ((time()-$st > $timeout) || ($req = $http->request($search))) { sleep(.1); } if ($req ne "200") { if ($req eq "") { return "Error: Timeout"; } else { return "Error: $http->status_message(); } } else { return $http->body(); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Making Timeout for Yourself
by pg (Canon) on Dec 31, 2003 at 20:51 UTC | |
by mcogan1966 (Monk) on Jan 05, 2004 at 13:14 UTC | |
|
Re: Making Timeout for Yourself
by hardburn (Abbot) on Dec 31, 2003 at 20:19 UTC | |
by mcogan1966 (Monk) on Dec 31, 2003 at 20:53 UTC | |
by hardburn (Abbot) on Dec 31, 2003 at 21:05 UTC | |
|
Re: Making Timeout for Yourself
by revdiablo (Prior) on Dec 31, 2003 at 20:12 UTC | |
by pg (Canon) on Dec 31, 2003 at 21:17 UTC | |
by revdiablo (Prior) on Jan 01, 2004 at 01:23 UTC | |
by mcogan1966 (Monk) on Dec 31, 2003 at 20:47 UTC |