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(); } }
In reply to Making Timeout for Yourself by mcogan1966
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |