本文整理汇总了PHP中swoole_server::connection_list方法的典型用法代码示例。如果您正苦于以下问题:PHP swoole_server::connection_list方法的具体用法?PHP swoole_server::connection_list怎么用?PHP swoole_server::connection_list使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类swoole_server
的用法示例。
在下文中一共展示了swoole_server::connection_list方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: broadcast
function broadcast(swoole_server $serv, $fd = 0, $data = "hello")
{
$start_fd = 0;
echo "broadcast\n";
while (true) {
$conn_list = $serv->connection_list($start_fd, 10);
if ($conn_list === false) {
break;
}
$start_fd = end($conn_list);
foreach ($conn_list as $conn) {
if ($conn === $fd) {
continue;
}
$ret1 = $serv->send($conn, $data);
//var_dump($ret1);
//$ret2 = $serv->close($conn);
//var_dump($ret2);
}
}
}
示例2: function
<?php
$serv = new swoole_server("0.0.0.0", 9501);
//这里监听了一个UDP端口用来做内网管理
$serv->addlistener('127.0.0.1', 9502, SWOOLE_SOCK_UDP);
$serv->on('connect', function ($serv, $fd) {
echo "Client:Connect.\n";
});
$serv->on('receive', function (swoole_server $serv, $fd, $from_id, $data) {
$info = $serv->connection_info($fd, $from_id);
//来自9502的内网管理端口
if ($info['server_port'] == 9502) {
$serv->send($fd, "welcome admin\n");
$start_fd = 0;
while (true) {
$conn_list = $serv->connection_list($start_fd, 10);
if ($conn_list === false) {
break;
}
$start_fd = end($conn_list);
var_dump($conn_list);
foreach ($conn_list as $conn) {
if ($conn === $fd) {
continue;
}
$serv->send($conn, "hello from {$fd}\n");
}
}
} else {
$serv->send($fd, 'Swoole: ' . $data);
}