onError

说明:

  1. callback Worker::$onError

当客户端的连接上发生错误时触发。

目前错误类型有

1、调用Connection::send由于客户端连接断开导致的失败 (code:WORKERMAN_SEND_FAIL msg:client closed)

2、在触发onBufferFull后,仍然调用Connection::send,并且发送缓冲区仍然是满的状态,导致发送失败 (code:WORKERMAN_SEND_FAIL msg:send buffer full and drop package)

3、使用AsyncTcpConnection异步连接失败时 (code:WORKERMAN_CONNECT_FAIL msg:stream_socket_client返回的错误消息)

回调函数的参数

$connection

连接对象,连接对象的说明见下一节

$code

错误码

$msg

错误消息

范例

  1. use Workerman\Worker;
  2. require_once __DIR__ . '/Workerman/Autoloader.php';
  3. $worker = new Worker('websocket://0.0.0.0:8484');
  4. $worker->onError = function($connection, $code, $msg)
  5. {
  6. echo "error $code $msg\n";
  7. };
  8. // 运行worker
  9. Worker::runAll();