Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm using the LWP::UserAgent Module with ActiveState Perl and Win NT. The timeout method doesn't seem to change anything about the HTTP requests. Is this not implemented in the Windows Module or am I reading the documentation wrong? If so can someone please tell me how to set the timeouts for my HTTP requests?

Replies are listed 'Best First'.
Re: HTTP timeout problems
by jbert (Priest) on Mar 23, 2000 at 17:04 UTC
    I suspect that the timeout option does not change the HTTP request (as you observe). Instead, perhaps, it sets a timer which returns control to your code if a response has not been received when the timeout expires?

    <rummages through docs> aha...yes...it uses 'alarm' to implement timeouts. We're on the right track.

    The activestate docs tell us that 'alarm' is not supported in their Win32 port.

    A (very) quick look at the LWP::UserAgent.pm code on the Activestate build seem to show that the calls to alarm have been stripped out.

    So it seems as though you won't have this functionality in the Win32 port of this module without more effort.

    Can anyone confirm this?

    In the meantime, off the top of my head I can only think that the way to get his would be:

    - run the UserAgent as a sub-process using Win32::Process (this would be quite icky...you still have to pass the result back to your parent)
    - use the ->Wait() method on the 'process object' returned, to sleep until your timeout expires or the subprocess exits
    - kill the subprocess if the ->Wait returned the code which means "process still running"

    For bonus style points, wrap this functionality up in the module so the 'timeout' behaves the same as on UNIX and send a patch to the maintainer. :-)

    Hope someone else can come up with a better solution.