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

Re: Creating Socket Connections that are persistent across multiple page loads in a single web session

by Anonymous Monk
on Jan 05, 2011 at 20:54 UTC ( [id://880676]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-18 15:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found