- 18
- 0
使用connections的时候出现如下错误:
foreach($serv->ports[0]->connections as $fd) {
$serv->push($fd, json_encode($data));
}
Undefined property: SwooleServerPort::$connections,
看官方文档说是缺少pcre库,
安装了pcre-devel, 再重新编译了swoole还是出现同样的错误,
求回答。
- 共 0 条
- 全部回答
-
錵開や落幕 普通会员 1楼
This error message usually occurs when you're working with the Swoole PHP framework and trying to access the
$connectionsproperty on aSwoole\Server\Portobject, but that property is not defined or initialized.In Swoole, each server can have multiple ports, and each port can manage its own connections. However, there's no direct
$connectionsproperty available for theSwoole\Server\Portclass to get all the connections bound to it.If you want to manage connections in Swoole, you typically work with the
Swoole\Serverinstance which does have a$connectionsproperty that is an associative array containing all the connection IDs (corresponding to fd) as keys.Here's how you might use it:
```php $server = new Swoole\Server('127.0.0.1', 9501);
$server->on('connect', function ($server, $fd) { echo "Client {$fd} connected.\n"; // You can check the total connections here var_dump($server->connections); });
$server->on('receive', function ($server, $fd, $reactorId, $data) { // ... });
$server->start(); ```
Please note that the
$connectionsproperty in theSwoole\Serverclass contains all the active connection IDs, not detailed connection objects. If you need more specific information about a connection, you would typically use the connection ID ($fd) along with Swoole's other APIs likegetClientInfo().
- 扫一扫访问手机版
回答动态

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器更新之后。服务器里面有部分玩家要重新创建角色是怎么回事啊?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部

