Score:0

Strange issue with Pthreads - Why is there a delay in each new Thread Submit when opcache.enable_cli is disabled?

jp flag

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.

Anyone ?

Michael Hampton avatar
cz flag
Threaded PHP has been a minefield of bugs and other problems for about as long as it has existed. It sounds like little has changed. It's best avoided if possible.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.