Home  >  Article  >  Backend Development  >  Advantages and disadvantages of PHP multi-processing and multi-threading

Advantages and disadvantages of PHP multi-processing and multi-threading

藏色散人
藏色散人forward
2019-12-05 13:29:162512browse

The advantages and disadvantages of PHP multi-process and multi-thread

Multi-process

1. When using multi-process, after the child process ends, the kernel Will be responsible for recycling resources

2. When using multiple processes, the abnormal exit of the child process will not cause the entire process Thread to exit. The parent process will also have the opportunity to rebuild the process.

3. A resident main process, It is only responsible for task distribution, and the logic is clearer.

4. The multi-process method is more stable, and data sharing can also be achieved using inter-process communication (IPC).

5. Shared memory, this method is the same as reading and writing variables between threads. It needs to be locked, and there will be synchronization and deadlock problems.

6. Message queue, you can use multiple sub-processes to grab the queue mode, the performance is very good

Multi-threading

1. Threads are in the same Within a process, memory variables can be shared to achieve inter-thread communication

2. Threads are more lightweight than processes. Opening a large number of processes will consume more system resources than threads

3. Multi-threading There are also some problems:

4. There are synchronization problems when threads read and write variables, and locks are required

5. There are performance problems if the lock granularity is too large, which may result in only one thread running. , other threads are waiting for the lock

6. Using multiple locks at the same time has complicated logic. Once a lock is not released correctly, a thread deadlock may occur

7. A certain thread A fatal error will cause the entire process to crash

For more PHP related knowledge, please visit PHP Tutorial!

The above is the detailed content of Advantages and disadvantages of PHP multi-processing and multi-threading. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete