Home >PHP Framework >Swoole >Can PHPfpm and swoole coexist?

Can PHPfpm and swoole coexist?

(*-*)浩
(*-*)浩Original
2019-12-12 10:50:093050browse

Swoole: The PHP asynchronous network communication engine for production environments enables PHP developers to write high-performance asynchronous concurrent TCP, UDP, Unix Socket, HTTP, and WebSocket services.

Can PHPfpm and swoole coexist?

Swoole can be widely used in the Internet, mobile communications, enterprise software, cloud computing, online games, Internet of Things (IOT), Internet of Vehicles, smart homes and other fields.

Using PHP Swoole as a network communication framework can greatly improve the efficiency of enterprise IT R&D teams and focus more on developing innovative products. (Recommended learning: swoole video tutorial)

php-fpm long connection              

Mainly maintain TCP long connection in php-fpm With the SWOOLE_KEEP option provided by the swoole extension, after the client sets this option, the connection will not be closed when the request ends, and the TCP connection can be reused after new requests arrive.

In addition, the bottom layer has built-in long connection detection capability.

When executing $client->connect(), it automatically detects whether the connection is available. If the reused connection has expired, the bottom layer will re-create a new TCP long connection.

Automatically clean up junk data when executing $client->connect() to avoid service exceptions caused by residual data from the last client timeout

$socket = new \swoole_client(SWOOLE_SOCK_TCP | SWOOLE_KEEP, WOOLE_SOCK_SYNC);
$socket->set(array(
    'open_length_check' => true,
    'package_max_length' => $this->packet_maxlen,
    'package_length_type' => 'N',
    'package_body_offset' => RPCServer::HEADER_SIZE,
    'package_length_offset' => 0,
));

The above is the detailed content of Can PHPfpm and swoole coexist?. 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