http://www.perlmonks.org?node_id=666272

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 });

Replies are listed 'Best First'.
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