bug: php8执行GatewayClient\Gateway::getAllGroupIdList();多次后,只能得到空数组

0

用定时器不断执行 Gateway::getAllGroupIdList();刚开始有用,几分钟后只能得到空数组。Gateway::getAllClientIdCount()得到0


有没有办法销毁Gateway,重新连接?


尝试:定时器每3秒重复运行:


\GatewayClient\Context::clear();
Gateway::$registerAddress = '127.0.0.1:9138';
$aaa = Gateway::getAllUidList();

在php7.4.8没问题。在php8.0.3报错:


  thrown

at vendor/workerman/gatewayclient/Gateway.php:450
446▕ $uid_map = array();
447▕ foreach ($data as $local_ip => $buffer_array) {
448▕ foreach ($buffer_array as $local_port => $items) {
449▕ //$items = ['connection_id'=>['uid'=>x, 'group'=>[x,x..], 'session'=>[..]], 'client_id'=>[..], ..];
➜ 450▕ foreach ($items as $connection_id => $info) {
451▕ if (!empty($info['uid'])) {
452▕ $uid_map[$info['uid']] = $info['uid'];
453▕ }
454▕ }

Whoops\Exception\ErrorException

Uncaught ErrorException: foreach() argument must be of type array|object, bool given in /var/www/html/vendor/workerman/gatewayclient/Gateway.php:450
Stack trace:
#0 /var/www/html/vendor/workerman/gatewayclient/Gateway.php(450): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'foreach() argum...', '/var/www/html/v...', 450)
#1 /var/www/html/app/Http/Controllers/Index/Reload.php(2121): GatewayClient\Gateway::getAllUidList()

截图

已邀请:

dignfei - 丹妮

赞同来自:

php4.8不会这样。 php8开启jit会这样

evilk

赞同来自:

现阶段,还是用php7.4,比较稳妥

dignfei - 丹妮

赞同来自:

找到了原因,这个方法,在php8中运行多次后会出错:
GatewayClient\GatewayProtocol的encode方法:
{


    /**
* 获取整个包的 buffer
*
* @param mixed $data
* @return string
*/
public static function encode($data)
{
$flag = (int)is_scalar($data['body']);
if (!$flag) {
$data['body'] = serialize($data['body']);
}
$data['flag'] |= $flag;
$ext_len = strlen($data['ext_data']);
$package_len = self::HEAD_LEN + $ext_len + strlen($data['body']);
return pack("NCNnNnNCnN", $package_len,
$data['cmd'], $data['local_ip'],
$data['local_port'], $data['client_ip'],
$data['client_port'], $data['connection_id'],
$data['flag'], $data['gateway_port'],
$ext_len) . $data['ext_data'] . $data['body'];
}

但是不知道是哪里错了,需要重复运行多次之后才会出错

要回复问题请先登录注册