OpenSwoole Server getClientInfo()

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5


<?php OpenSwoole\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

  • The client certificate can only be obtained if the call is made within the callback of onConnect.
  • You will have to parse a client certificate using openssl_x509_parse
  • If using dispatch modes 1 or 3, take into consideration that these modes are using a stateless model, so related client information will be cleared from memory when the connection is broken or finishes so when calling this method in these modes, the data returned may be for another connection



$info = $server->getClientInfo($fd);


// Array of data returned
array(5) {
  string(9) ""

Data Information

  • reactor_id: Which Reactor thread the connection is from
  • server_fd: Which listening port socket the connection comes from, this is not the fd of the client connection, the server
  • server_port: The port of the server, the listening port used
  • remote_port: The port the client connects to
  • remote_ip: The IP address of the client connection
  • connect_time: The time the client connects to the Server, in seconds, set by the master process
  • last_time: The time of the last data received, in seconds, set by the master process
  • close_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 list
  • recv_queued_bytes: The amount of data waiting to be processed
  • send_queued_bytes: The amount of data waiting to be sent
  • websocket_status: [Optional] WebSocket connection status, this information will be added when the server is a OpenSwoole\WebSocket\Server
  • uid: [Optional] This information will be added when the user ID is bound with the server bind method
  • ssl_client_cert: [Optional] This information will be added when the client has set the certificate, only available when called from onConnect
Last updated on September 1, 2022