Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5
<?php OpenSwoole\Server->getClientList(int $startFd = 0, int $pageSize = 10): bool|array
The starting file descriptor number to begin from as clients connect based on a fd number that increases
How many items are kept per page, the maximum shall not exceed 100
If success, it returns a numeric array based on the starting $fd
, otherwise it returns false
. The array is sorted from smallest to largest
Get a list of all the TCP connections for all the workers, based on a starting file descriptor, the default is 0 so that means to collect all information for all connected TCP clients.
This method is based shared memory operation, meaning it is fast and does not block, purely asynchronous.
Things to Consider
Server::$connections
iterator to traverse these connectionsOpenSwoole\Server::SIMPLE_MODE
mode, only the connection of the current process can obtained<?php
$start_fd = 0;
while(true)
{
$conn_list = $server->getClientList($start_fd, 10);
if($conn_list === false or count($conn_list) === 0)
{
echo "finish\n";
break;
}
$start_fd = end($conn_list);
var_dump($conn_list);
foreach($conn_list as $fd)
{
$server->send($fd, "broadcast");
}
}