People compare PHP with other software development languages. According to many articles, there is one major difference: PHP does not support asynchronous processing, threading, etc. Working as an Apache module, that’s correct. But if you’re running your script on CLI or CGI module you have an option: Fork.
Fork is a child processing method. As different from your regular PHP scripts, pcntl_fork() is not linear. Because of this, for some developers, it’s a little bit hard to learn how fork works.
All processes you run have a unique process id. We call that id PID. All processes also have another ID which is reference to the parent process. We call that id PPID. pcntl_fork() is just copying current process and pretend as it’s a child process. New child process gets a unique PID and our process’s PID becomes PPID for new child process.
When you call pcntl_fork() it always returns INT value. For child processes, it returns 0. For parent, it returns PID if everything’s fine. Otherwise, it returns -1. When you get -1 that means something is just wrong.