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

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

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

 

  1. if ($this->_status === self::STATUS_CLOSING) { 
  2. $this->destroy(); 
  3. } 
  4. if ($this->_status === self::STATUS_CLOSED) { 
  5. $this->onConnect = null; 
  6. } 
  7. return; 
  8. } 
  9. // Add socket to global event loop waiting connection is successfully established or faild. 
  10. Worker::$globalEvent->add($this->_socket, EventInterface::EV_WRITE, array($this, 'checkConnection')); 
  11. // For windows. 
  12. if(DIRECTORY_SEPARATOR === '\\') { 
  13. Worker::$globalEvent->add($this->_socket, EventInterface::EV_EXCEPT, array($this, 'checkConnection'));

已邀请:

hw524926 - 90后新人

赞同来自:

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

keytehu

赞同来自:

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

要回复问题请先登录注册