zeromq / php-zmq

ZeroMQ for PHP
http://pecl.php.net/zmq
Other
551 stars 119 forks source link

PHP Fatal error: Uncaught exception 'ZMQSocketException' with message 'Failed to send message: Interrupted system call' #141

Closed cmosguy closed 9 years ago

cmosguy commented 9 years ago

I am not sure what I could possibly be doing wrong here. I am implementing a simple zmq message into my ratchet websocket framework.

I am getting the error message:

PHP Fatal error:  Uncaught exception 'ZMQSocketException' with message 'Failed to send message: Interrupted system call'

Not sure what I am doing wrong here. Here is the server code:

  //Listen for web server to make ZeroMQ push after an ajax request
        $context = new Context($loop);

        $pull = $context->getSocket(\ZMQ::SOCKET_PULL);
        $pull->bind(\Config::get('squarekings.zmqserver') . ':' . $port); // Binding to 127.0.0.1 means the only client that can connect is itself
        $pull->on('message', array($pusher, 'onGameUpdate'));
        $pull->on('square', array($pusher, 'onSquareUpdate'));

        // Set up our WebSocket server for clients wanting real-time updates
        $webSock = new Server($loop);
        $webSock->listen(8080, '0.0.0.0'); // Binding to 0.0.0.0 means remotes can connect
        $webServer = new IoServer(
            new HttpServer(
                new WsServer(
                    new WampServer(
                        $pusher
                    )
                )
            ),
            $webSock
        );

Then when i am trying to send the message or update for the request I have the following:

  $this->socket = $context->getSocket(\ZMQ::SOCKET_PUSH, 'my pusher');
            $this->socket->connect(\Config::get('squarekings.zmqserver') . ":" . \Config::get('squarekings.zmqport'));
 $this->socket->send(json_encode($arr));

I don't understand how to debug this and what is going on with the handling of the ZMQ messages. Can someone please advise how I could fix this issue?

Thanks!

mkoppanen commented 9 years ago

Does this happen every time you send or when terminating the program (for example CTRL+C)?

cmosguy commented 9 years ago

Hi @mkoppanen, thanks for getting back to me.

This is happening when i am running my script from a command line tool called tinker . I have not tried it from a script or anything like that, just from this interactive shell. I am assuming the same results if I use it from the script.

Is there a way to debug this? What is going on behind the scenes with zmq to result this error do you think?

Thanks

maxymajzr commented 9 years ago

It's not ZMQ's fault in this case, it's most likely something that the mentioned utility does. Is it forking at any point?

cmosguy commented 9 years ago

@Majeh and @mkoppanen looks like you guys are right. It isn't ZMQ, it is the stupid tinker system I am using that is screwing things up. I should have tested this with an isolated test in a script. Thanks for your help!

Rastusik commented 5 years ago

@mkoppanen I have the same problem when using ZMQ with Swoole (which seems to fork php processes) ... Is this extension compatible with such a use case?

duckboy81 commented 4 years ago

Not to turn this into stackoverflow, but for future folks finding themselves here, you may seek to reorganize your code to bind or connect AFTER your fork occurs.

Moving my $rep->connect("ipc://" . self::ZQM_SOCKET_PATH); to a function call after I forked has solved the problem.

Rastusik commented 4 years ago

yeah, I figured that as well, but I think, that that's just a workaround, isn't it?