onBufferDrain

Description:

callback Worker::$onBufferDrain

Each connection has a separate application layer send buffer, and the buffer size is determined by TcpConnection::$maxSendBufferSize, defaulting to 1MB. You can manually set and modify the size, and changes will take effect for all connections.

This callback is triggered after all data in the application layer send buffer has been sent. It is generally used in conjunction with onBufferFull, for instance, to stop sending data to the peer when onBufferFull is triggered, and to resume writing data when onBufferDrain is triggered.

Parameters of the Callback Function

$connection

The connection object, which is a TcpConnection instance, used for manipulating the client connection, such as sending data, closing the connection, and so on.

Example

use Workerman\Worker;
use Workerman\Connection\TcpConnection;
require_once __DIR__ . '/vendor/autoload.php';

$worker = new Worker('websocket://0.0.0.0:8484');
$worker->onBufferFull = function(TcpConnection $connection)
{
    echo "bufferFull and do not send again\n";
};
$worker->onBufferDrain = function(TcpConnection $connection)
{
    echo "buffer drain and continue send\n";
};
// Run the worker
Worker::runAll();

Note: In addition to using anonymous functions as callbacks, you can also refer to this for other callback writing methods.

See Also

onBufferFull Triggered when the application's send buffer of the connection is full.