Ratchet send doesn't work with the sleep function, how can I fix this?
Here is my code:
$i = 0;
while($i < 180)
{
foreach ($this->clients as $client)
{
$client->send($res->asXML()."\0");
}
sleep(2);
$i++;
}
It is not a good idea to use sleep() with ratchet. Instead it would be best to take advantage of its existing event loop.
I'm not sure what exactly you are trying to accomplish, but here is a basic example. I am willing to bet that you will need to re-work your code to accommodate this different technique.
//Start the server
$server = IoServer::factory(
new WsServer($session),
$port,
$addr
);
//Attach the loop
$server->loop->addPeriodicTimer(2, function () {
$client->send($res->asXML()."\0");
});
Sources:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With