Of course, I run regular queue employees using Pheanstalk. It works something like this:
The parent PHP process returns the specified number of worker processes. Each worker uses Pheanstalk to connect to beanstalkd and waits for work. When an employee receives a task, he performs the task, and then leaves, freeing his memory. Then the parent PHP process creates a new worker for the replacement.
Your requirement is something like this:
The parent PHP process uses proc_open () to develop the python interpreter process by storing references to the generated STDIN and STDOUT pipes. Then the parent PHP process enters the loop, using Pheanstalk to connect to the beanstalk and reserve the next job. When the job is reserved, PHP uses the fwrite () command to send the contents of the job to the python STDIN pipe, and then uses fread () to read the response from the python's STDOUT protocol.
It is assumed that you want to support a running python process, rather than starting a new python process every time a job is reserved.
Crazy anyway, but it can work.
The saner variant will use the Python beanstalkd client, but hey, great to see more people using Pheanstalk :)
Cheers, Paul
source share