Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP async process communication

Is there a way to achieve inter-process (or threading) communication in PHP, but still keep everything run asynchronous?

I want to have a script that creates 4 processes and then terminates immediately. Each of the 4 processes should do an action and when finished it should notify someone (another script maybe?) that it finished. So I want to know when all of the 4 scripts are done, so I can update my status from retrieving to done.

Is this possible? Preferably without re-compiling PHP (I read this is required for working with threads), but I will do that if necessary.

like image 851
Eduard Luca Avatar asked Jul 12 '26 22:07

Eduard Luca


2 Answers

As others have mentioned, Gearman is one solution. The other, one I actually prefer, is creating an asynchronous message queue where you add jobs on the job stack.

I'm using ZeroMQ for such purposes, and there's a PHP framework available that implements ZeroMQ for async tasks called Photon. Browsing Photon's source might give you some ideas on how to implement async job queue in case you decide to go with it.

like image 82
N.B. Avatar answered Jul 15 '26 11:07

N.B.


Gearman may provide what you are looking for.

like image 33
Jeremy Harris Avatar answered Jul 15 '26 11:07

Jeremy Harris