use Swoole\Coroutine;
use function Swoole\Coroutine\run;
// 一键协程化
Coroutine::set(['hook_flags'=> SWOOLE_HOOK_UDP]);
run(function() {
$socket = stream_socket_server(
'udp://0.0.0.0:6666',
$errno,
$errstr,
STREAM_SERVER_BIND
);
if (!$socket) {
echo "$errstr ($errno)" . PHP_EOL;
exit(1);
}
while (stream_socket_recvfrom($socket, 1, 0)) {
}
});