账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    Undefined property: Swoole\Server\Port::$connections
    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
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 錵開や落幕 普通会员 1楼

      This error message usually occurs when you're working with the Swoole PHP framework and trying to access the $connections property on a Swoole\Server\Port object, 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 $connections property available for the Swoole\Server\Port class to get all the connections bound to it.

      If you want to manage connections in Swoole, you typically work with the Swoole\Server instance which does have a $connections property 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 $connections property in the Swoole\Server class 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 like getClientInfo().

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部