OpenSwoole\Server->on('BufferEmpty', fn)

Latest version: pecl install openswoole-26.11.1 | composer require openswoole/core:26.11.1

Declaration

<?php OpenSwoole\Server->on('BufferEmpty', Callable $callback)

Parameters

event

The event callback name.

callback

Callable event function, called as function (OpenSwoole\Server $server, int $fd).

Return

success

If success, it returns true, otherwise it returns false.

Description

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.

Example

<?php
$server->on('BufferEmpty', function(OpenSwoole\Server $server, int $fd)
{
    echo "Send buffer of connection #{$fd} is empty, continue sending\n";
});
Last updated on November 20, 2026