workerman发送数据大于8192,出错

ocean

发送小于8192的数据,没有问题。
当数据大于8192,通过回调继续发送,但是在添加回调时,会出现PHP Warning,回调添加失败,造成后面的数据没有发送。
添加回调代码

Worker::$globalEvent->add($this->_socket, EventInterface::EV_WRITE, array($this, 'baseWrite'));

出现的PHP Warning
Warning: event_set(): 'Array' is not a valid callback in /****/vendor/workerman/workerman/Events/Libevent.php on line 106 event_del_: event has no event_base set.
 
Linux:Centos , php,libevent信息

libevent support => enabled
extension version => 0.1.0
Revision => $Revision$
libevent version => 2.1.8-stable
2356 2 1
2个回答

walkor 打赏

Worker::$globalEvent->add($this->_socket, EventInterface::EV_WRITE, array($this, 'baseWrite'));这句是你手动调用的?
是否更改了workerman代码?
 

  • ocean 2019-01-14

    TcpConnection send方法中的代码
    if ($this->_sendBuffer === '') {
    $len = @fwrite($this->_socket, $send_buffer , 8192);
    // send successful.
    if ($len === strlen($send_buffer)) {
    return true;
    }
    // Send only part of the data.
    if ($len > 0) {
    $this->_sendBuffer = substr($send_buffer, $len);
    } else {
    // Connection closed?
    if (!is_resource($this->_socket) || feof($this->_socket)) {
    self::$statistics['send_fail']++;
    if ($this->onError) {
    try {
    call_user_func($this->onError, $this, WORKERMAN_SEND_FAIL, 'client closed');
    } catch (\Exception $e) {
    Worker::log($e);
    exit(250);
    } catch (\Error $e) {
    Worker::log($e);
    exit(250);
    }
    }
    $this->destroy(self::DESTROY7);
    return false;
    }
    $this->_sendBuffer = $send_buffer;
    }
    Worker::$globalEvent->add($this->_socket, EventInterface::EV_WRITE, array($this, 'baseWrite'));

  • walkor 2019-01-14

    应该是你改动了workerman代码导致的。看下baseWrite方法是不是public

  • ocean 2019-01-14

    是public。只是在TcpConnection中,添加了一下属性字段,这个应该不影响吧

  • ocean 2019-01-14

    workerman 版本是 const VERSION = '3.4.8';

  • walkor 2019-01-15

    应该是改动源码导致的

  • ocean 2019-01-16

    修改send方法中,打包的代码造成的,已解决

ocean

问题已解决

  • 暂无评论
年代过于久远,无法发表回答
×
🔝