onError
Description:
callback Worker::$onError
Triggered when an error occurs on the client connection.
Currently, the types of errors are as follows:
-
Failure caused by calling
Connection::senddue to the client connection being closed (which will immediately trigger theonClosecallback)(code:WORKERMAN_SEND_FAIL msg:client closed) -
After triggering
onBufferFull(when the send buffer is full), ifConnection::sendis called again and the send buffer is still full, it causes a send failure (this will not trigger theonClosecallback)(code:WORKERMAN_SEND_FAIL msg:send buffer full and drop package) -
When using
AsyncTcpConnectionfails to connect (which will immediately trigger theonClosecallback)(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.