The php Function Pcntl_Fork
The php function pcntl_fork is a useful function that allows a parent process to spawn a child process which continues processing from the line below the call to the function. Normally all variables and objects etc are shared by the processes but when you call pcntl_fork they become copies which belong to the new process. So modifying them in the new process has no effect on the values in the parent (or any other forked) processes.
But forking can be a little tricky to manage. Unless you take care of a few things it can be difficult to get your PHP program to work properly. The problem is that a forked program consists of multiple processes which each have their own private copy of the state of your script (and extensions). This can cause problems when trying to maintain connections to database servers or open files and network sockets.
For this reason you should avoid using pcntl_fork in production code unless it is absolutely necessary. Instead try to use a message queue or run the script in lower-level language such as C. The latter approach will also allow you to detach the background process which is a big advantage in terms of managing a forked PHP script.
If you need to spawn multiple processes then consider using threading. This is more efficient than spawning them all via pcntl_fork as it uses multiple processors rather than just one.