Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 棘轮发送不';不能使用睡眠功能_Php_Sleep_Ratchet - Fatal编程技术网

Php 棘轮发送不';不能使用睡眠功能

Php 棘轮发送不';不能使用睡眠功能,php,sleep,ratchet,Php,Sleep,Ratchet,Ratchet send无法使用sleep功能,如何解决此问题 这是我的密码: $i = 0; while($i < 180) { foreach ($this->clients as $client) { $client->send($res->asXML()."\0"); } sleep(2); $i++; } $i=0; 而($iclients as$client) { $client->send($res-

Ratchet send无法使用
sleep
功能,如何解决此问题

这是我的密码:

$i = 0;
while($i < 180)
{
    foreach ($this->clients as $client)
    {

       $client->send($res->asXML()."\0");
    }
    sleep(2);
    $i++;
}
$i=0;
而($i<180)
{
foreach($this->clients as$client)
{
$client->send($res->asXML()。“\0”);
}
睡眠(2);
$i++;
}

将sleep()与棘轮一起使用不是一个好主意。相反,最好利用其现有的事件循环

我不确定你到底想完成什么,但这里有一个基本的例子。我敢打赌,您将需要重新编写代码以适应这种不同的技术

//Start the server
$server = IoServer::factory(
    new WsServer($session),
    $port,
    $addr
);

//Attach the loop
$server->loop->addPeriodicTimer(2, function () {
    $client->send($res->asXML()."\0");
});
资料来源:


  • 不。舞台调度。事件环你怎么能修好它?不要调用
    sleep()