ext-swooleis supported until v4.7.1, use
ext-openswoole>= v4.7.1. Latest version:
pecl install openswoole-4.9.1
<?php Swoole\Coroutine\Client->recv(float $timeout = 0): string|bool
The timeout period of how long to wait to receive data, in seconds. So 1.5 is 1.5 seconds.
If the remote server connection returns an empty string, it means the server has closed the connection and if there was an error,
false will be returned, check the reason why with
$client->errCode. For a successful return, see API description.
Receive data from the remote server connection.
EOF/Length checking is enabled, the client will returns the whole package, check the client configuration on how to setup EOF checking and protocol analysis.
When the server is successfully sending back data to receive, the client processes it differently depending on how you have it setup.
Protocol Has Been Set: If you have the communication protocol set with your client, like
SWOOLE_SOCK_TCP, then only complete data will be returned, a whole package will be read but the limit is determined by
package_max_length, check the configuration on how to change this.
Protocol Not Set: If you have not set a communication protocol, then the client can only receive up to 64K of data, this is the default when no protocol is set. When no communication protocol is set, you must then implement your own protocol parsing in PHP for network processing, as the data may come in using a specific format.
$client->errCode to check for the last known error.
If you specify a timeout and if it is reached the error code will be
See the timeout guide to understand how to setup timeouts.
For a working example, see the full TCP/UDP client example.