Keep It Simple, Stupid | |
PerlMonks |
Making Timeout for Yourselfby mcogan1966 (Monk) |
on Dec 31, 2003 at 19:46 UTC ( [id://317980]=perlmeditation: print w/replies, xml ) | Need Help?? |
I've been working on a project now for a couple of months. This project involved polling a number of websites, and getting specific information from that page. 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.
Back to
Meditations
|
|