English 中文(简体)
零MQ PHP 超时
原标题:ZeroMQ PHP Timeout

我对我的 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?

问题回答

您不需要调查即可发送简单信息。 我认为 < code> pUSH socket 将更好地为您服务。 设定一个合理的剩余值, 这将试图向 < code> PULL socket 对应方发送信息, 不管它是否在监听 。

$context = new ZMQContext();
$socket = new ZMQSocket($context, ZMQ::SOCKET_PUSH);
$socket->setSockOpt(ZMQ::SOCKOPT_LINGER, 2000);
$socket->connect("tcp://localhost:5557");
$socket->send($data);




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签