in reply to Creating Socket Connections that are persistent across multiple page loads in a single web session

#!/usr/bin/perl -w use strict; package MyConnections; use vars ($dbh); unless($dbh) { # do stuff here, establish connection/etc } 1; Then simply include a module as similar to the above if you're already using Apache mod_perl/registry. The module remains persistent (compiled) per each HTTPD process Apache spawns, thus any program which uses the above module would have access to the already instantiated $dbh. We use this method for memcached and database handles - the only caveat being that you have to manage one connection per httpd process on the server but it works very well.
  • Comment on Re: Creating Socket Connections that are persistent across multiple page loads in a single web session

Replies are listed 'Best First'.
Re^2: Creating Socket Connections that are persistent across multiple page loads in a single web session
by unlinker (Monk) on Jan 06, 2011 at 10:31 UTC

    Thank you for your advice. I have recently moved away from mod_perl to relying on Plack-based frameworks. The problem I am trying to solve is having a single socket per authenticated-session rather than one per httpd process.

    However the principal part of your suggestion (if I have understood you correctly): keep the socket creation code in a separate module that is different from the code that handles the web request is clearly the way to go in any persistent web framework. So thanks for that.