Home  >  Article  >  PHP Framework  >  How to make a long connection with swoole

How to make a long connection with swoole

(*-*)浩
(*-*)浩Original
2019-12-09 09:34:363895browse

How to make a long connection with swoole

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn