As far as I can remember, PHP has always had a terrible reputation at handling very heavy (or asynchronous) tasks. For a long while if you wanted to parallelize long tasks you had to resort to forking through pcntl_fork which had its own issues, and you couldn't really handle the results of those tasks properly, etc.
As such, a habit has kind of developed where we go straight for more intricate solutions such as queuing (which just delays your task if anything), React PHP, or even using another language altogether. But PHP can do threading, and more importantly it's a lot easier than you probably think.
In this article I'm going to dive into the pthreads extension (short for POSIX Threads). It has been around for a while (since 2012) but I feel like too many people forget it exists or assume it is going to be painful to use – mostly because the official documentation is rather slim about it.
(Score: 2) by Bill Evans on Thursday November 26 2015, @02:21AM
Almost always subprocesses are better. Even where there has to be ongoing communication between the mother process and the daughter process, using a pty is cleaner than using pthreads: cleaner in that the processes do not share their heap memory, thus making bugs easier to isolate. The only time I use pthreads is in the (rare) case where speed of execution is an issue. I think the most recent time was about six years ago.