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

hw524926

上代码

$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'));
阅读 1619
3个回答

hw524926

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

  • 暂无评论
keytehu

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

  • 暂无评论
1171659744_php

有大佬解决了吗

  • 暂无评论