Illegal offset type in isset or empty

ray

PHPSocket.io服务启动后,启动通信就报错
"Illegal offset type in isset or empty","file":"\socket\vendor\workerman\phpsocket.io\src\Event\Emitter.php","line":85
此报错是概率性的,肯定是我的业务代码出了问题,但是想知道下这个报错会是因为什么原因引起,因为Chrome浏览器通信时候没有这个报错,业务代码正常运行,偶尔会报此错误,使用火狐浏览器通信,就一定报此错误,希望可以提供一些提示信息,筛查了很久了没有头绪

2175 1 0
1个回答

walkor 打赏

截图
看起来是这个$event_name 传的值有问题,应该是个字符串,但是传递了数组或者对象。

用这个代码调试试下,看下$event_name是什么值,调用栈是什么。

if (!is_scalar($event_name)) {
    var_dump($event_name);
    echo new \Exception('bad event_name)');
}

socket.io是早期为了兼容不支持websocket的浏览器的产物,现在基本上所有设备都支持websocket了,没必要用socket.io了。

  • ray 2022-01-24

    class Closure#42 (2) {
    virtual $closure =>
    "$this->PHPSocketIO{closure}"
    public $static =>
    array(3) {
    'sent' =>
    bool(false)
    'id' =>
    int(1)
    'self' =>
    class PHPSocketIO\Socket#35 (17) {
    public $nsp =>
    class PHPSocketIO\Nsp#2 (11) {
    ...
    }
    public $server =>
    class PHPSocketIO\SocketIO#3 (10) {
    ...
    }
    public $adapter =>
    class PHPSocketIO\DefaultAdapter#4 (4) {
    ...
    }
    public $id =>
    string(24) "de38b1c2837bd841053e58ec"
    public $path =>
    string(1) "/"
    public $request =>
    class PHPSocketIO\Engine\Protocols\Http\Request#41 (12) {
    ...
    }
    public $client =>
    class PHPSocketIO\Client#34 (9) {
    ...
    }
    public $conn =>
    class PHPSocketIO\Engine\Socket#32 (16) {
    ...
    }
    public $rooms =>
    array(1) {
    ...
    }
    public $_rooms =>
    array(0) {
    ...
    }
    public $flags =>
    array(0) {
    ...
    }
    public $acks =>
    array(0) {
    ...
    }
    public $connected =>
    bool(true)
    public $disconnected =>
    bool(false)
    protected $_eventListenerMap =>
    array(2) {
    ...
    }
    public $handshake =>
    array(8) {
    ...
    }
    public $timer_id =>
    int(16)
    }
    }
    public $this =>
    class PHPSocketIO\Socket#35 (17) {
    public $nsp =>
    class PHPSocketIO\Nsp#2 (11) {
    public $name =>
    string(1) "/"
    public $server =>
    class PHPSocketIO\SocketIO#3 (10) {
    ...
    }
    public $rooms =>
    array(0) {
    ...
    }
    public $flags =>
    array(0) {
    ...
    }
    public $sockets =>
    array(1) {
    ...
    }
    public $connected =>
    array(1) {
    ...
    }
    public $fns =>
    array(0) {
    ...
    }
    public $ids =>
    int(0)
    public $acks =>
    array(0) {
    ...
    }
    protected $_eventListenerMap =>
    array(1) {
    ...
    }
    public $adapter =>
    class PHPSocketIO\DefaultAdapter#4 (4) {
    ...
    }
    }
    public $server =>
    class PHPSocketIO\SocketIO#3 (10) {
    public $nsps =>
    array(1) {
    ...
    }
    protected $_nsp =>
    string(16) "\PHPSocketIO\Nsp"
    protected $_socket =>
    string(19) "\PHPSocketIO\Socket"
    protected $_adapter =>
    string(27) "\PHPSocketIO\DefaultAdapter"
    public $eio =>
    NULL
    public $engine =>
    class PHPSocketIO\Engine\Engine#7 (10) {
    ...
    }
    protected $_origins =>
    string(3) ":"
    protected $_path =>
    NULL
    public $sockets =>
    class PHPSocketIO\Nsp#2 (11) {
    ...
    }
    public $worker =>
    class Workerman\Worker#6 (27) {
    ...
    }
    }
    public $adapter =>
    class PHPSocketIO\DefaultAdapter#4 (4) {
    public $nsp =>
    class PHPSocketIO\Nsp#2 (11) {
    ...
    }
    public $rooms =>
    array(1) {
    ...
    }
    public $sids =>
    array(1) {
    ...
    }
    public $encoder =>
    class PHPSocketIO\Parser\Encoder#5 (1) {
    ...
    }
    }
    public $id =>
    string(24) "de38b1c2837bd841053e58ec"
    public $path =>
    string(1) "/"
    public $request =>
    class PHPSocketIO\Engine\Protocols\Http\Request#41 (12) {
    public $onData =>
    NULL
    public $onEnd =>
    NULL
    public $httpVersion =>
    string(3) "1.1"
    public $headers =>
    array(14) {
    ...
    }
    public $rawHeaders =>
    array(14) {
    ...
    }
    public $method =>
    string(3) "GET"
    public $url =>
    string(45) "/socket.io/?EIO=3&transport=polling&t=Nw9wi8F"
    public $connection =>
    NULL
    public $_query =>
    array(3) {
    ...
    }
    public $res =>
    NULL
    public $onClose =>
    NULL
    public $cleanup =>
    NULL
    }
    public $client =>
    class PHPSocketIO\Client#34 (9) {
    public $server =>
    class PHPSocketIO\SocketIO#3 (10) {
    ...
    }
    public $conn =>
    class PHPSocketIO\Engine\Socket#32 (16) {
    ...
    }
    public $encoder =>
    class PHPSocketIO\Parser\Encoder#39 (1) {
    ...
    }
    public $decoder =>
    class PHPSocketIO\Parser\Decoder#36 (1) {
    ...
    }
    public $id =>
    string(24) "de38b1c2837bd841053e58ec"
    public $request =>
    class PHPSocketIO\Engine\Protocols\Http\Request#41 (12) {
    ...
    }
    public $nsps =>
    array(1) {
    ...
    }
    public $connectBuffer =>
    array(0) {
    ...
    }
    public $sockets =>
    array(1) {
    ...
    }
    }
    public $conn =>
    class PHPSocketIO\Engine\Socket#32 (16) {
    public $id =>
    string(24) "de38b1c2837bd841053e58ec"
    public $server =>
    class PHPSocketIO\Engine\Engine#7 (10) {
    ...
    }
    public $upgrading =>
    bool(true)
    public $upgraded =>
    bool(false)
    public $readyState =>
    string(4) "open"
    public $writeBuffer =>
    array(0) {
    ...
    }
    public $packetsFn =>
    array(0) {
    ...
    }
    public $sentCallbackFn =>
    array(0) {
    ...
    }
    public $request =>
    class PHPSocketIO\Engine\Protocols\Http\Request#41 (12) {
    ...
    }
    public $remoteAddress =>
    string(15) "127.0.0.1:49534"
    public $checkIntervalTimer =>
    int(19)
    public $upgradeTimeoutTimer =>
    int(17)
    public $pingTimeoutTimer =>
    int(20)
    protected $_eventListenerMap =>
    array(3) {
    ...
    }
    public $transport =>
    class PHPSocketIO\Engine\Transports\PollingXHR#31 (12) {
    ...
    }
    public $upgradeTransport =>
    class PHPSocketIO\Engine\Transports\WebSocket#33 (9) {
    ...
    }
    }
    public $rooms =>
    array(1) {
    'de38b1c2837bd841053e58ec' =>
    string(24) "de38b1c2837bd841053e58ec"
    }
    public $_rooms =>
    array(0) {
    }
    public $flags =>
    array(0) {
    }
    public $acks =>
    array(0) {
    }
    public $connected =>
    bool(true)
    public $disconnected =>
    bool(false)
    protected $_eventListenerMap =>
    array(2) {
    'showDataInit' =>
    array(1) {
    ...
    }
    'disconnect' =>
    array(1) {
    ...
    }
    }
    public $handshake =>
    array(8) {
    'headers' =>
    array(14) {
    ...
    }
    'time' =>
    string(28) "Mon Jan 24 2022 10:29:30 GMT"
    'address' =>
    string(15) "127.0.0.1:49534"
    'xdomain' =>
    bool(true)
    'secure' =>
    bool(false)
    'issued' =>
    int(1642991370)
    'url' =>
    string(45) "/socket.io/?EIO=3&transport=polling&t=Nw9wi8F"
    'query' =>
    array(3) {
    ...
    }
    }
    public $timer_id =>
    int(16)
    }
    }
    Exception: bad event_name in D:\www\socket\vendor\workerman\phpsocket.io\src\Event\Emitter.php:89
    Stack trace:

    0 [internal function]: PHPSocketIO\Event\Emitter->emit(Object(Closure))

    1 D:\www\socket\vendor\workerman\phpsocket.io\src\Socket.php(307): call_user_func_array(Array, Array)

    2 D:\www\socket\vendor\workerman\phpsocket.io\src\Socket.php(269): PHPSocketIO\Socket->onevent(Array)

    3 D:\www\socket\vendor\workerman\phpsocket.io\src\Client.php(202): PHPSocketIO\Socket->onpacket(Array)

    4 [internal function]: PHPSocketIO\Client->ondecoded(Array)

    5 D:\www\socket\vendor\workerman\phpsocket.io\src\Event\Emitter.php(97): call_user_func_array(Array, Array)

    6 D:\www\socket\vendor\workerman\phpsocket.io\src\Parser\Decoder.php(34): PHPSocketIO\Event\Emitter->emit('decoded', Array)

    7 D:\www\socket\vendor\workerman\phpsocket.io\src\Client.php(182): PHPSocketIO\Parser\Decoder->add('21["showDataIni...')

    8 [internal function]: PHPSocketIO\Client->ondata('21["showDataIni...')

    9 D:\www\socket\vendor\workerman\phpsocket.io\src\Event\Emitter.php(97): call_user_func_array(Array, Array)

    10 D:\www\socket\vendor\workerman\phpsocket.io\src\Engine\Socket.php(187): PHPSocketIO\Event\Emitter->emit('data', '21["showDataIni...')

    11 [internal function]: PHPSocketIO\Engine\Socket->onPacket(Array)

    12 D:\www\socket\vendor\workerman\phpsocket.io\src\Event\Emitter.php(97): call_user_func_array(Array, Array)

    13 D:\www\socket\vendor\workerman\phpsocket.io\src\Engine\Transport.php(56): PHPSocketIO\Event\Emitter->emit('packet', Array)

    14 D:\www\socket\vendor\workerman\phpsocket.io\src\Engine\Transports\Polling.php(151): PHPSocketIO\Engine\Transport->onPacket(Array)

    15 D:\www\socket\vendor\workerman\phpsocket.io\src\Engine\Transports\Polling.php(120): PHPSocketIO\Engine\Transports\Polling->onData('27:421["showDat...')

    16 [internal function]: PHPSocketIO\Engine\Transports\Polling->dataRequestOnEnd(Object(PHPSocketIO\Engine\Protocols\Http\Request))

    17 D:\www\socket\vendor\workerman\phpsocket.io\src\Engine\Protocols\SocketIO.php(177): call_user_func(Array, Object(PHPSocketIO\Engine\Protocols\Http\Request))

    18 D:\www\socket\vendor\workerman\phpsocket.io\src\Engine\Protocols\SocketIO.php(89): PHPSocketIO\Engine\Protocols\SocketIO::emitEnd(Object(Workerman\Connection\TcpConnection), Object(PHPSocketIO\Engine\Protocols\Http\Request))

    19 D:\www\socket\vendor\workerman\phpsocket.io\src\Engine\Protocols\SocketIO.php(61): PHPSocketIO\Engine\Protocols\SocketIO::onData(Object(Workerman\Connection\TcpConnection), '27:421["showDat...')

    20 D:\www\socket\vendor\workerman\workerman\Connection\TcpConnection.php(601): PHPSocketIO\Engine\Protocols\SocketIO::input('POST /socket.io...', Object(Workerman\Connection\TcpConnection))

    21 D:\www\socket\vendor\workerman\workerman\Events\Select.php(294): Workerman\Connection\TcpConnection->baseRead(Resource id #51)

    22 D:\www\socket\vendor\workerman\workerman\Worker.php(2418): Workerman\Events\Select->loop()

    23 D:\www\socket\vendor\workerman\workerman\Worker.php(1406): Workerman\Worker->run()

    24 D:\www\socket\vendor\workerman\workerman\Worker.php(1349): Workerman\Worker::forkWorkersForWindows()

    25 D:\www\socket\vendor\workerman\workerman\Worker.php(542): Workerman\Worker::forkWorkers()

    26 D:\www\socket\nobox.php(399): Workerman\Worker::runAll()

    27 {main}

  • ray 2022-01-24

    前期是为了快速开发,socket.io封装好的使用起来比较简易,后期开发发现局限性确实是有的,那么是推荐直接用workerman么

  • walkor 2022-01-24

    如果是聊天类即时通讯推荐gatewayWorker

  • walkor 2022-01-24

    phpsocket.io项目后面可能就不维护了

  • ray 2022-01-24

    上边的异常信息,您这边能看出什么异常么

  • walkor 2022-01-24

    event_name 应该是字符串,但是传给了一个闭包函数导致的,具体什么原因不清楚。

  • ray 2022-01-24

    这个是在emit里用了回调函数直接反馈数据了,一个前端页面用一个这样的长链接没问题,用了两三个之后就有这个问题了
    $socket->on('showDataInitNumber', function($msg, $ack) {

        //顶部数字跳动数据初始化 
        $data_nums = getTodayInfo($msg);
        $ack(json_encode($data_nums));
    });
  • walkor 2022-01-24

    可能phpsocket.io ack这里有bug。

  • ray 2022-01-24

    我这边主要是与Android设备以及浏览器做实时通信的,有那个框架比较方便开发这个而且长期维护的啊。。socket.io不维护了那我只能年后用新框架再重构一遍了

  • walkor 2022-01-24

    gatewayWorker 或者 webman/push插件 都可以

  • ray 2022-01-24

    谢谢解惑

  • ray 2022-02-14

    walkor大佬好,使用phpsocket.io主要是为了与java服务中的socket进行数据对接,也就是其中封装好的emit方法以及emit方法中的ack回调,您推荐的gatewayWorker和webman/push插件中没有找到对应的方法,里边的封装协议也没有相关讯息,这个有什么现有的解决方案么

  • walkor 2022-02-14

    没有

年代过于久远,无法发表回答
×
🔝