Process communication:
1. Interrupt system
2. Unnamed pipe [half-duplex communication]
can only be used for parent and child processes , communication between sibling processes without a name is called an unnamed pipe. The transmitted data is unformatted. Both parties can define the format themselves and do not rely on the file system.
Recommendation: "PHP Tutorial"
3. Named pipes
are used for troublesome operations that cannot be achieved by unnamed pipes, even for processes that have nothing to do with them. Can communicate [it depends on a file descriptor, but this file is a FIFO type file, that is, a pipeline file, and adheres to the FIFO principle, that is, the queue is first in, first out]
PS: Be sure to understand process blocking, non Blocking principle, pipeline file, process [running status transfer]
Examples of application scenarios: If you use PHP's socket API to write a network framework similar to Workerman, you can perform unified interrupt signal event processing
The interrupt handler is only responsible for accepting interrupt requests and writing data through the pipe write end. The main process listens for events on the file descriptor [readable events]. You can privately check out the stream socket related API and learn about the IO multiplexing function. How to use】Reprocess. The interrupt handler will not be left waiting for too long.
Of course, communication between cross-language processes can also be achieved through named pipes.
$filePath = $argv[1]; if (posix_mkfifo($filePath,0666)<0){ fprintf(STDOUT,"命名管道创建错误"); exit(0); } $fd = fopen($filePath,"w"); while (is_resource($fd)){ fprintf(STDOUT,">"); $data = fgets(STDIN); if ($data){ fwrite($fd,$data,strlen($data)); } } exit(0);
The above is the detailed content of Multi-process named pipe communication [unrelated processes] PHP version. For more information, please follow other related articles on the PHP Chinese website!