I've successfully configured and used gearman and its pecl php extension. I'm using it to execute a long process concerning long sql queries in a background. I'm using Yii btw, if that detail helps.
Here's how I use it :
public function actionProcessWithGearman(){
$output = shell_exec('gnome-terminal -e "php workers/worker.php" > /dev/null 2>/dev/null &');
$client = new GearmanClient();
$client->addServer();
$result = $client->doBackground('executeJob',//parameters);
}
Some details:
If you notice I run a gnome-terminal first, so that I can see the process rather than going directly with the php command, I also added /dev/null so that it will no longer wait for a response. And then the worker is woken up and runs the job.
Problem:
My problem arises when this action is executed several times or executed by several users in different clients, and as a result, multiple terminals running worker.php are being instantiated.
How do I have only one worker? and even if I can have several workers for several users in the different clients, how do I close a worker everytime the task is finished?