Bill Moseley <[EMAIL PROTECTED]> writes:

> Looking at some older code I see I was jumping through hoops for keep alives.
> 
> What I want is a way to nicely handle the situation where keep alive
> support isn't available for the current LWP installation.
> 
>     if ( $server->keep_alive ) {
> 
>         eval 'require LWP::Protocol::http11;';
>         if ( $@ ) {
>             warn "Cannot use keep alives -- $@\n";
>         } else {
>             LWP::Protocol::implementor('http', 'LWP::Protocol::http11');
>         }
>     } else {
>         require LWP::Protocol::http;
>         LWP::Protocol::implementor('http', 'LWP::Protocol::http');
>     }

Yup, just remove all this code :-)

> Also, how can I report the number of connections? I'd like to see how many
> connections compared to number of requests.

You can't (not directly at least). You can ask the LWP::ConnCache how
many connections it currently is holding on to.

If you want the number you could probably subclass LWP::ConnCache,
override the "dropping" method to count connections.

> Also, how do I determine how large to set the connection cache?  

How many connections do you want to allow out at any time?
LWP can't keep more than one of them busy at any time.
I would not set this number higher than say 4.

> For example, say I'm spidering my own site, so I want keep_alive set.  I'm
> also validating links to our image server, so I want keep alive's there.
> I'm also validating links to remote sites, where I don't really need keep
> alives.

You can enable keep alive for LWP::UserAgent and then disable it for
individual requests by adding a "Connection: close" header to them.

Regards,
Gisle

Reply via email to