Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Using Persistent Connections with SOAP::Lite HTTP clients

by tomhukins (Curate)
on Feb 05, 2008 at 12:39 UTC ( #666272=snippet: print w/ replies, xml ) Need Help??

Description:

By default, SOAP::Lite creates new HTTP or HTTPS connections for every request. This makes long transactions run slowly, particularly over HTTPS where the SSL/TLS handshake takes place every time.

SOAP::Lite::Transport::HTTP::Client contains a hack to support the "Connection: Keep-Alive" header field in HTTP requests, but I've had no luck making it work.

LWP::UserAgent contains its own connection caching mechanism that allows it to use persistent connections. As SOAP::Lite::Transport::HTTP::Client subclasses LWP::UserAgent, we can initialise the connection cache on the SOAP transport object.

# $client should contain a SOAP::Lite client that uses HTTP/HTTPS

# Cache up to 10 connections
my $max_connections = 10;

# Retrieve the HTTP Transport object.
my $transport = $client->transport();
# Use LWP::UserAgent's conn_cache() method.
$transport->conn_cache({ total_capacity => $max_connections });
Comment on Using Persistent Connections with SOAP::Lite HTTP clients
Download Code
Re: Using Persistent Connections with SOAP::Lite HTTP clients
by ddn123456 (Pilgrim) on Aug 27, 2010 at 13:46 UTC

    Great snippet! Thanks.

    FYI. As of http 1.1, the persistent connection (KeepAlive header) is set to true by default.

    However if the server responds with a Connection: close header, the tcp (and ssl) connection between client and server is no longer persistent. The soap session may remain in place however depending on the soap client-server application communication.

    It also implies that the server is not configured or not able to maintain or support persistent connections.

    With kind regards.

    ddn123456

      I agree with everything you write, but I suspect you have misunderstood what my code does: it sets a request header in order to allow the server to leave the connection open after sending its response.

      The snippet I posted sets Connection: KeepAlive on the request, letting the server know that the client can deal with KeepAlive responses.

      Although HTTP 1.1 introduced this feature, clients and servers commonly support it as an extension when speaking HTTP 1.0: if the header does not exist, servers will close the TCP connection after each request as per standard HTTP 1.0.

        Hi,

        Thanks for the clarification.

        Reading it now afterwards I didn't express myself clearly enough perhaps but I did understand your code snippet perfectly.

        It does remain a nice snippet :-)

        Greetings.
        ddn123456

Back to Snippets Section

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://666272]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2014-12-29 17:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (194 votes), past polls