onError

Description:

callback Worker::$onError

Triggered when an error occurs on the client connection.

Currently, the types of errors are as follows:

  1. Failure caused by calling Connection::send due to the client connection being closed (which will immediately trigger the onClose callback) (code:WORKERMAN_SEND_FAIL msg:client closed)

  2. After triggering onBufferFull (when the send buffer is full), if Connection::send is called again and the send buffer is still full, it causes a send failure (this will not trigger the onClose callback) (code:WORKERMAN_SEND_FAIL msg:send buffer full and drop package)

  3. When using AsyncTcpConnection fails to connect (which will immediately trigger the onClose callback) (code:WORKERMAN_CONNECT_FAIL msg:error message returned by stream_socket_client)

Callback Function Parameters

$connection

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

$code

Error code.

$msg

Error message.

Example

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

$worker = new Worker('websocket://0.0.0.0:8484');
$worker->onError = function(TcpConnection $connection, $code, $msg)
{
    echo "error $code $msg\n";
};
// Run the worker
Worker::runAll();

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