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.