I successfully used ZeroMQ with PHP and wrote a job server. I have an admin script that checks the server is up and doing something like pinging with a timeout.
Everything works fine when the server is running, but when it is turned off (and ZMQPoll
will expire as expected), my script does what it should - BUT
There seems to be no disconnect()
socket method, since I can tell PHP that the socket is dead and I don't want it to hang?
This is the code snippet below my admin script -
// ... // waiting for dead server on zmqsock to respond after sending a message // $poll = new ZMQPoll; $poll->add( $this->zmqsock, ZMQ::POLL_IN ); $readable = $writeable = array(); $poll->poll( $readable, $writeable, $timeout * 1000 ); if( $errors = $poll->getLastErrors() ) { foreach ( $errors as $err ) { throw new Exception($err); } } if( ! $readable ){ // clean up everything, raise errors, etc.. $poll->clear(); unset( $poll, $this->zmqsock, $this->zmqcontext ); // Script hangs here exit(0); } // ..
source share