PHP is often not suitable for resident shell processes, he does not have a dedicated GC routines, and there is no effective memory management path. So if you're using PHP as a resident shell, you'll always be abort and unhappy by memory exhaustion.
Moreover, if the input data is illegal, and the script is not detected, causing abort, it will also make you very unhappy.
That? What do we do?
Oh, don't worry, many processes to help you!
So, what is this for?
Advantages:
1. Using multiple processes, the kernel is responsible for reclaiming resources after the child process finishes
2. Using multiple processes, a subprocess exception exit does not cause the entire process thread to exit. The parent process also has the opportunity to rebuild the process.
3. A resident main process, which is only responsible for the distribution of tasks, has a clearer logic.
Then, how do you do it?
Next, we use the POSIX and PCNTL series functions provided by PHP to implement a PHP command parser that accepts user input and then executes the fork subprocess and is responsible for echoing the end state of the child process.
Code as follows, I added a note, if there is no understanding of the place, you can read the manual related functions, or reply to the message.