Join 4,000+ others and never miss out on new tips, tutorials, and more.
4.x is outdated, please check the latest version 22.x
Latest version:
pecl install openswoole-22.1.2
<?php Swoole\Server->getClientInfo(int $fd, int $reactorId, bool $ignoreError = false): bool|array
The file descriptor number of the client connection you get info for
The rector ID thread where the connection is located
Whether to ignore the fact that if a connection is closed, still return client information or only return information is the connection is still open, default is false
which means only when a connection is still open
If success, it returns an array, otherwise it returns false
.
Get client connection information, returns an array of information about a client for open or closed connections.
Things to Consider
onConnect
.openssl_x509_parse
<?php
$info = $server->getClientInfo($fd);
var_dump($info);
// Array of data returned
array(5) {
["from_id"]=>
int(3)
["server_fd"]=>
int(14)
["server_port"]=>
int(9501)
["remote_port"]=>
int(19889)
["remote_ip"]=>
string(9) "127.0.0.1"
["connect_time"]=>
int(1390212495)
["last_time"]=>
int(1390212760)
}
reactor_id
: Which Reactor thread the connection is fromserver_fd
: Which listening port socket the connection comes from, this is not the fd
of the client connection, the serverserver_port
: The port of the server, the listening port usedremote_port
: The port the client connects toremote_ip
: The IP address of the client connectionconnect_time
: The time the client connects to the Server, in seconds, set by the master processlast_time
: The time of the last data received, in seconds, set by the master processclose_errno
: The error code of the closed connection. If the connection is closed abnormally, the value of close_errno
is non-zero. You can refer to the Linux error message listrecv_queued_bytes
: The amount of data waiting to be processedsend_queued_bytes
: The amount of data waiting to be sentwebsocket_status
: [Optional] WebSocket connection status, this information will be added when the server is a Swoole\WebSocket\Serveruid
: [Optional] This information will be added when the user ID is bound with the server bind methodssl_client_cert
: [Optional] This information will be added when the client has set the certificate, only available when called from onConnect