我对我的 PHP 脚本通过 ZeroMQ 与 PHP 守护程序在后端运行并等待信件有问题。 如果守护程序在请求的php 下方等待无休止的时间 。 如果我重新装入页面, firefox 结束在无休止的循环中, 我不得不重新启动 apache2 来扼杀运行中的请求。 特别是在守护程序未完成的开发中, 这真的很烦人。 有人知道我如何设定一个超时, 或者在守护程序无法到达时跳过请求( 然后发送一个消息, 服务器在下方, 并发送错误)?
我试过这样:
$context = new ZMQContext(1);
$req = new ZMQSocket($context, ZMQ::SOCKET_REQ);
$req->connect("tcp://localhost:5557");
$read = $write = array();
// Poll socket for a reply, with timeout
$poll = new ZMQPoll();
$poll->add($req, ZMQ::POLL_OUT);
$events = $poll->poll($read, $write, 3000);
$errors = $poll->getLastErrors();
if($errors)
echo "No connection";
else
echo "connection";
... $data = ....
$req->send(json_encode($data));
2nd Question, I use PHP-Daemon from shaneharter, sometimes when the daemon does not start correctly because of errors or I shut it down with CRTL+C zeromq still reserves the address, when I restart the daemons it throws an exception, this address is already in use. Can I easily destroy all ZeroMQ connections?