Join 4,000+ others and never miss out on new tips, tutorials, and more.
pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5
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
OpenSwoole\Constant::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.