Home > PHP Framework > Swoole > body text

How to make a long connection with swoole

(*-*)浩
Release: 2019-12-09 09:34:36
Original
3903 people have browsed it

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!