phpmysqlapachecrongearman

(having the process run until completion, after browser is closed)


I have a website, created using PHP and running on Apache. I want a subscriber to be able to log in and start a process on the server. They can then log out or close the browser without interrupting the process. Later they can log in and see the progress or see the results of the original process. What is the best way to accomplish this (having the process run until completion, after the browser is closed)?

Just looking for someone to point me in the right direction. A few people mentioned Gearman.


Solution

  • Gearman would be an ideal candidate, and I would use it for exactly the purpose you describe. It has everything you need out of the box to meet your requirements ("background" a long running, CPU-bound process to another machine, e.g. video encoding).

    There is a Gearman PHP library, but you can write your worker code in a different language if it's better suited to doing the work.

    For reporting progress information, I recommend having the worker write to Redis or Memcached - some kind of temporary storage that your web server can also access.

    Check out the simple PHP example on the Gearman site. For learning, I recommend setting up a lab environment that contains 3 separate VM's, one for your web server (the client), one for the Gearman job queue (the server) and another for processing jobs (the workers).