How to communicate between processes swoole

 

 

Way communication process between Swoole

Pipeline pipe

Data exchange between the pipes for the process, Linux system itself provides a pipe function creates a half-duplex communication pipe. Half-duplex communication in only one way flow of data (write-only end end of the read-only), only with the use of genetic relationship between process (parent and child) is.

Interprocess communication IPC pipeline is the most basic way, there are two types of pipes are named pipes, anonymous pipes.

Anonymous pipes: designed for between processes with blood, and complete the data transfer. Named pipes: can be used between any two processes, Swoole in the pipeline are anonymous pipe.

And using eventfd UnixSock two pipes Swoole package so that the communication between the process more flexible.

Swoole the Process module built pipelines way for inter-process communication, in the construction of the Process instance just open the $ pipe_type options, Swoole underlying automatically creates a pipe, where the description of the need, although the name is called on the pipeline, but in fact the underlying communication is achieved through UnixSock Swoole in the new version, the Linux Pipe so it is not in the true sense.

Create a process

 

 

$ Pipe_type type of pipe can be divided into three types:

0 means no creation pipeline

1 represents the creation SOCK_STREAM types of pipes

2 represents the creation SOCK_DGRAM types of pipes

When enabled $ redirect_stdin_stdout, $ pipe_type option ignores the user parameters, forced to 1.

Pipe descriptors

When the process is fork out, Process Object parent and child process will be provided on a member variable named pipe, and storing the underlying UnixSocket descriptor, the parent and child processes may transmit data via the pipe descriptors, and Process can directly call provides read / write interfaces to transmit and receive data.

 

 

Pipeline to read and write

swoole_process-> write (string $ data) write data to process in the pipeline

swoole_process-> read (int $ buffer_size = 8192) to read data from the pipe in the process

These are the details of how communication between swoole process, more please pay attention to me.

There need to learn to communicate Swoole friends please join our exchange group together, there is a problem with the exchange, progress together! Provided that you are learning technology. Thanks for reading!

Click here to join the group jq.qq.com

 

Guess you like

Origin www.cnblogs.com/heyue0117/p/11973746.html