Вот код, который у меня сейчас есть:
Код: Выделить всё
// Create a channel with space for 1000 messages
$chan = new OpenSwoole\Coroutine\Channel(1000);
co::run(function () use ($chan){
// Listener
go(function() use ($chan) {
// Read from channel
while (1) {
$data_read = $chan->pop();
echo ("Data read: $data_read\n");
}
});
});
// UDP server
// Set coroutine options before the server is started
OpenSwoole\Coroutine::set([
'enable_coroutine' => true
]);
// Start a new UDP server on 12.0.0.1, listening on port 9502
$server = new OpenSwoole\Server('127.0.0.1', 9502, OpenSwoole\Server::POOL_MODE, OpenSwoole\Constant::SOCK_UDP);
// Setup the incoming data event callback, called 'Packet'
$server->on('Packet', function ($server, $data, $clientInfo) use ($chan)
{
echo ("Data written: $data\n");
$chan->push($data);
});
// Start the server and begin accepting incoming requests
$server->start();
Код: Выделить всё
===================================================================
[FATAL ERROR]: all coroutines (count: 1) are asleep - deadlock!
===================================================================
Подробнее здесь: https://stackoverflow.com/questions/790 ... -a-channel