Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by gman (Friar)
on Jan 05, 2011 at 12:08 UTC ( [id://880581]=note: print w/replies, xml ) Need Help??


in reply to Re^6: Creating Socket Connections that are persistent across multiple page loads in a single web session
in thread Creating Socket Connections that are persistent across multiple page loads in a single web session

I have done this using the POE framework. I keep a persistent connection to two tcp servers and marshal all CGI connections through them, keeping track using unique Ids and using JSON for passing the data between them.

use POE qw(Component::Schedule Filter::Reference Component::Server::TCP Component::Client::TCP Filter::Line Component::Log4perl Component::Daemon );
  • Comment on Re^7: Creating Socket Connections that are persistent across multiple page loads in a single web session
  • Download Code

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

    Thanks for the suggestion. Have not used POE before (but have read a bit about it in Simon Cozens book "Advanced Perl Programming") so will pass it for now, in favour of a simple Dancer function that hands out sockets to requestors. This function keeps track of which socket belongs to which requestor using a hash whose keys are session ids. If the session id is a key in the hash it just hands out the corresponding socket, if not it creates a new one, records it in the hash and hands it out. Since I run the Dancer app under Starman, I believe the handed sockets would be persistent.

    Would POE give me a more robust solution than this obviously simplistic method? If yes, I would love to give it a go.

      I am unfamiliar with Dancer, is this the method used or an application? I have had my POE app in production for about 3 months now with %100 uptime. My first thought was to use threads, I have done similar in Java. But never used POE before, so thought I would give it a try and keep the site all perl. I send a keep alive every so many seconds to each server, and have a very low query rate. Currently I run about 150 query a day and each one make several exchanges with the servers for each query.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2025-11-16 18:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (72 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.