Questions about Pheanstalk

I am looking to run a persistent instance of the python interpreter that can be passed. The entire system designed for this will be written in PHP. I noticed the Pheanstalk package for use in the beanstalkd work queue. Has anyone used Pheanstalk to create (and maintain) an ongoing process? I understand that the usual use of Pheanstalk is to run scripts or other tasks that take long periods of time in an asynchronous issue to avoid waiting for the user. I am looking, asynchronously, for a Pheanstalk work / process that controls and maintains a python interpreter process to which I can pass input. Is this possible, was it done, and if so, how?

+4
source share
1 answer

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

+4
source

All Articles