Member-only story
True PHP7 Multi-Threading: How to Rebuild PHP and use pthreads
Building PHP on Mac and Linux with Multi-Threading and pthreads examples

Your PHP apps could really do with multi-threading capabilities for running tasks in parallel, but you know the PHP building process can be troublesome and time consuming — not only this, migrating your production server PHP to a new build also sounds like a headache. Well, things are not all bad if we utilise a couple of PHP utilities at our disposal to aid the process.
This article will walk you through this process of compiling a new, multi-threading capable PHP build, before migrating to that version, then demonstrate how to code multi-threaded applications with the pthreads extension.
Off-the-shelf PHP builds from package managers do not support multi-threading. What we need to do is rebuild PHP with a flag that enables ZTS, or “Zend Thread Safety”, which then allows us to expand our thread use. To facilitate this build process we will utilise a tool named phpbrew, designed to build multiple versions of PHP and switch between them with ease. Then, only once our builds are completed can we experiment with pthreads.
There are some platform specific gotchas, but we will overcome these with simple solutions.