So for context, I am running PHP-FPM 7.4 on Ubuntu and I compiled it with ZTS. Then added the extensions Pthreads and ZSTD .
I am running a few hundred tasks and I need them to spawn new php processes as fast as possible, but after multiple tests I realized although my script was running in 0.001 secs, each time I spawned a new PHP Thread with Pthreads it added 0.01sec to the equation, which makes the time of each loop iteration multiply by 10 .
I am trying to find possible explanations for this for a couple of weeks already, and so far after doing multiple tests and tweaking a lot of settings the only thing that made sense is that this is a Pthreads Limitation by design .
Next logical step would be to update the code to the newer Parallel project but in the meantime I found something curious , when I enable opcache.enable_cli in PHP FPM config the issue is almost gone and most of the threads do not get delayed !
Sadly, this causes constant zend_mm_heap corruption / segmentation fault errors which from what I have read can’t really be fixed (its either a zend or pthreads core issue) , but it would seem like it’s a good start to understanding the root of the problem.