tp5.1里直接使用AsyncTcpConnection方法,报错Call to a member function add() on null

0

上代码


$connection = new AsyncTcpConnection('tcp://baidu.com:81');
// 执行连接的时候还没设置onError回调
$connection->connect();
$connection->onError = function($connection, $err_code, $err_msg)
{
echo "$err_code, $err_msg";
};

报错
ThrowableError in AsyncTcpConnection.php line 203 致命错误: Call to a member function add() on null


if ($this->_status === self::STATUS_CLOSING) { 
$this->destroy();
}
if ($this->_status === self::STATUS_CLOSED) {
$this->onConnect = null;
}
return;
}
// Add socket to global event loop waiting connection is successfully established or faild.
Worker::$globalEvent->add($this->_socket, EventInterface::EV_WRITE, array($this, 'checkConnection'));
// For windows.
if(DIRECTORY_SEPARATOR === '\\') {
Worker::$globalEvent->add($this->_socket, EventInterface::EV_EXCEPT, array($this, 'checkConnection'));
已邀请:

hw524926 - 90后新人

赞同来自:

我的async没放在worker的onWokerStart里,是在代码里直接使用的

keytehu

赞同来自:

AsyncTcpConnection 只能在workerman的运行环境中使用吧

要回复问题请先登录注册