Is the php process a long connection?

(*-*)浩
Release: 2023-02-27 15:24:01
Original
2211 people have browsed it

A complete software system is mostly composed of multiple processes working together, even if they are on the same server. Therefore, efficient communication between processes is crucial.

Is the php process a long connection?

As a scripting language, PHP is not process-resident like C/Java, so it uses short connections to connect to back-end services.

Voiceover: A friend said that extensions can be written in C? (Recommended learning: PHP video tutorial)

Is the php process a long connection?

The above picture is a typical scenario. The site PHP is deployed on machine A, and the cache memcache is deployed on machine A. On B, they communicate through short connections. The process is:

(1) PHP establishes a tcp short connection;

(2) Send data according to the memcache protocol;

( 3) Receive the data returned by memcache;

(4) PHP closes the tcp short connection;

When the traffic is small, there is no problem with the above process. When the website traffic is very large, the short connection It may become a performance bottleneck. Is there any optimization method?

Voiceover: Establishing and destroying connections is time-consuming.

Changing the topic, what is UNIX Domain Socket?

UNIX Domain Socket is an IPC mechanism. It does not need to go through the network protocol stack, packaging and unpacking, calculation of checksums, maintenance of sequence numbers and responses, etc. It just transfers application layer data from a Process is copied to another process.

Voiceover: IPC, Inter-Process Communication, inter-process communication.

It can be used for two unrelated processes on the same host, and is full-duplex, providing an IPC mechanism for reliable message delivery (messages are not lost, not repeated, and not messed up).

Voiceover: Kinship refers to a "special" process relationship such as father-son process or brother process.

It can be seen that the efficiency of UNIX Domain Socket will be much higher than that of TCP short connection, but it can only be used for process communication between the same host, and PHP applications and back-end services are often deployed in different On the machine, can it be used for optimization at this time?

Is the php process a long connection?

The optimized simple architecture diagram is as above:

(1) Deploy a local-proxy on the php application server;

(2) UNIX Domain Socket is used to communicate between php and local-proxy;

(3) TCP long connection communication between local-proxy and the back-end service;

This greatly improves communication efficiency and eliminates the overhead of establishing and closing TCP short connections for each request

The above is the detailed content of Is the php process a long connection?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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