Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Mojolicious: keeping track of connections with forking

by Rodster001 (Pilgrim)
on May 15, 2017 at 17:03 UTC ( [id://1190325]=perlquestion: print w/replies, xml ) Need Help??

Rodster001 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I have a mojolicious project which I developed using the morbo development web server. Now I am ready to deploy using hypnotoad but I have run into an issue.

I am keeping track of client "session" connections, like this:
my $clients = {}; websocket '*' => sub { my $c = shift; my $socket_id = $c->tx->connection; $clients->{$socket_id} = $c->tx; };
And then sending messages to each client of that "session":
foreach my $socket_id (keys %{ $clients }) { $clients->{$socket_id}->send({ json => { message => "hi" } }); }
This works great under morbo. But not so under hypnotoad. I believe it is because hypnotoad forks and the socket ids of child processes are not shared across children. So either one child cannot send messages to another, or I need a different way of identifying/finding sockets of children.

And honestly I am not 100% sure if I have fully understood the problem yet. Any help would be greatly appreciated!

Replies are listed 'Best First'.
Re: Mojolicious: keeping track of connections with forking
by Anonymous Monk on May 15, 2017 at 19:20 UTC
    you need a background process or database to synchronize
      I keep track of everything in memory with memcache. Like I said, it works great with morbo. But the forking in hypnotoad breaks it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1190325]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (7)
As of 2024-03-19 09:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found