SWOOLE_KEEP Establishing a TCP persistent connection
swoole_client supports creating a TCP persistent connection in php-fpm/apache Service-Terminal. (Recommended learning: swoole video tutorial)
Usage:
$client = new swoole_client(SWOOLE_SOCK_TCP | SWOOLE_KEEP); $client->connect('127.0.0.1', 9501);
After enabling the SWOOLE_KEEP option, a request ends The socket will not be closed, and the last connection created will be automatically reused the next time you connect.
If you execute connect and find that the connection has been closed by the server, then connect will create a new connection.
Advantages of SWOOLE_KEEP
TCP long connection can reduce the extra IO consumption caused by connect 3 handshakes/close 4 wave waves
Reduce server side close/connect times
The above is the detailed content of How to make a long connection with swoole. For more information, please follow other related articles on the PHP Chinese website!