Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Keeping HTTP sessions alive

by Anonymous Monk
on Nov 20, 2003 at 16:25 UTC ( [id://308615]=perlquestion: print w/replies, xml ) Need Help??

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

G'Day Monks,

I'm working on a script to do some server testing. I need to go grab some webpages off of the server with LWP::UserAgent. Here's the trick though: I need to keep the HTTP connections open. So, after I fetch the page, I would like to keep the HTTP session open for some arbitrary amount of time afterward. Is this possible? The server does support KeepAlive, if that helps, but I find that doing this:

my $ua = LWP::UserAgent->new(keep_alive => undef); my $req = HTTP::Request->new(GET => $url); my $res = $ua->request($req);

simply fetches the webpage and doesn't keep the connection alive once it's done. Note that I used undef because according to CPAN documentation, that value is passed on to LWP::ConnCache as total_capacity. The LWP::ConnCache documentation says that if total_capacity is set to undef, the total capacity is unlimited.

If it's not possible to keep a connection alive after fetching a page, is it possible to simply open a connection and keep it alive (without ever fetching a page) instead?

Replies are listed 'Best First'.
Re: Keeping HTTP sessions alive
by davido (Cardinal) on Nov 20, 2003 at 18:32 UTC
    A quick search using SuperSearch for the term "keep_alive" turned up just a few threads... not a lot. I see that in this thread liz commented that not all HTTP servers support the keep_alive option. Are you sure yours does?

    Also, most of the examples I find set keep_alive to 1, not undef.

    Update: Looking into the Apache Webserver source provides some interesting information. At the following link you'll be able to look at just what is required before a connection can be kept alive: http://lxr.webperf.org/source.cgi/modules/http/http_protocol.c#206

    The important part starts around line 206:

    It appears that a number of criteria must be met for it to be possible to keep a session alive.

    Based on the above link, I would suggest checking the following:

    • Is your server configured to enable keep_alive?
    • Are you outputting HTTP v1.1 style requests?
    • Are you a buggy twit? (sorry, couldn't resist.. I have no idea what they mean by that)
    • Have the max number of connections been reached?
    • Have you set a resonable inter-request timeout?

    Hopefully that's enough to get you started.


    Dave


    "If I had my life to live over again, I'd be a plumber." -- Albert Einstein
Re: Keeping HTTP sessions alive
by IlyaM (Parson) on Nov 21, 2003 at 09:10 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://308615]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2024-04-24 10:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found