Php 棘轮发送不';不能使用睡眠功能
Ratchet send无法使用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-
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()
。