Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-26.11.1 | composer require openswoole/core:26.11.1
<?php OpenSwoole\Server->on('BufferEmpty', Callable $callback)
The event callback name.
Callable event function, called as function (OpenSwoole\Server $server, int $fd).
If success, it returns true, otherwise it returns false.
Execute the callback function when the send buffer of a connection, after it was full, has been drained to the low watermark, set with the buffer_low_watermark option (by default 0, so when the buffer is empty).
Use this event together with BufferFull to pause and resume sending data to a connection. When send_yield is enabled, coroutines waiting in $server->send() for this connection are resumed at the same time.
The callback receives the server object and the session ID $fd of the connection.
In OpenSwoole\Server::POOL_MODE this event can not be used with dispatch_mode 1, 3 or 7 unless enable_unsafe_event is set, the callback is ignored with a warning.
<?php
$server->on('BufferEmpty', function(OpenSwoole\Server $server, int $fd)
{
echo "Send buffer of connection #{$fd} is empty, continue sending\n";
});