PHPSocket.io服務啟動后,啟動通信就報錯
"Illegal offset type in isset or empty","file":"\socket\vendor\workerman\phpsocket.io\src\Event\Emitter.php","line":85
此報錯是概率性的,肯定是我的業(yè)務代碼出了問題,但是想知道下這個報錯會是因為什么原因引起,因為Chrome瀏覽器通信時候沒有這個報錯,業(yè)務代碼正常運行,偶爾會報此錯誤,使用火狐瀏覽器通信,就一定報此錯誤,希望可以提供一些提示信息,篩查了很久了沒有頭緒
看起來是這個$event_name 傳的值有問題,應該是個字符串,但是傳遞了數(shù)組或者對象。
用這個代碼調(diào)試試下,看下$event_name是什么值,調(diào)用棧是什么。
if (!is_scalar($event_name)) {
var_dump($event_name);
echo new \Exception('bad event_name)');
}
socket.io是早期為了兼容不支持websocket的瀏覽器的產(chǎn)物,現(xiàn)在基本上所有設備都支持websocket了,沒必要用socket.io了。
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:
這個是在emit里用了回調(diào)函數(shù)直接反饋數(shù)據(jù)了,一個前端頁面用一個這樣的長鏈接沒問題,用了兩三個之后就有這個問題了
$socket->on('showDataInitNumber', function($msg, $ack) {
//頂部數(shù)字跳動數(shù)據(jù)初始化
$data_nums = getTodayInfo($msg);
$ack(json_encode($data_nums));
});
walkor大佬好,使用phpsocket.io主要是為了與java服務中的socket進行數(shù)據(jù)對接,也就是其中封裝好的emit方法以及emit方法中的ack回調(diào),您推薦的gatewayWorker和webman/push插件中沒有找到對應的方法,里邊的封裝協(xié)議也沒有相關訊息,這個有什么現(xiàn)有的解決方案么