title: Start and stopping workers in gearman php
body: <p>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.</p>
  
  <p>Here's how I use it :</p>
  
  <pre><code>public function actionProcessWithGearman(){
  
  $output = shell_exec('gnome-terminal -e "php workers/worker.php" &gt; /dev/null 2&gt;/dev/null &amp;');
  
  
  $client = new GearmanClient();
  $client-&gt;addServer();
  $result = $client-&gt;doBackground('executeJob',//parameters);
  
  }
  </code></pre>
  
  <p><strong>Some details:</strong></p>
  
  <p>If you notice I run a <strong><em>gnome-terminal</em></strong> first, so that I can see the process rather than going directly with the <strong><em>php command</em></strong>, I also added <strong><em>/dev/null</em></strong> so that it will no longer wait for a response. And then the worker is woken up and runs the job. </p>
  
  <p><strong>Problem:</strong></p>
  
  <p>My problem arises when this action is <strong>executed several times or executed by several users in different clients</strong>, and as a result, multiple terminals running <strong>worker.php</strong> are being instantiated. </p>
  
  <p>How do I have <strong>only one worker?</strong> and even if I can have several workers for several users in the different clients, <strong>how do I close a worker everytime the task is finished?</strong></p>