title: Gearman Tasks Callback
body: <p>I have this simple code:</p>
  
  <pre><code>&lt;?php
  $client = new GearmanClient();
  
  // Add a server
  $client-&gt;addServer(); // by default host/port will be "localhost" &amp; 4730
  
  echo "Sending job\n";
  
  // Send job
  
  $data = file_get_contents('test.html');
  $client-&gt;addTask("convert", $data,null,1);
  $client-&gt;setCompleteCallback("complete");
  $client-&gt;runTasks();
  if (! $client-&gt;runTasks())
  {
      echo "ERROR " . $client-&gt;error() . "\n";
      exit;
  }
  else
  {
  
  }
  
  function complete($task) {
    echo "Success: $task-&gt;unique()\n";
    echo($task-&gt;data());
  }
  
  ?&gt;
  </code></pre>
  
  <p>and a worker :</p>
  
  <pre><code>&lt;?php
  
  // Create our worker object
  $worker = new GearmanWorker();
  
  // Add a server (again, same defaults apply as a worker)
  $worker-&gt;addServer();
  
  // Inform the server that this worker can process "reverse" function calls
  $worker-&gt;addFunction("convert", "convertToPDF");
  
  
  while (1) {
    print "Waiting for job...\n";
    $ret = $worker-&gt;work(); // work() will block execution until a job is delivered
    if ($worker-&gt;returnCode() != GEARMAN_SUCCESS) {
      break;
    }
  }
  
  function convertToPDF(GearmanJob $job) {
    $workload = $job-&gt;workload();
    $fd = fopen("temp.html", 'wr');
  
    fwrite($fd,$workload);
    exec('wkhtmltopdf temp.html test.pdf');
    $job-&gt;sendData(file_get_contents('test.pdf'));
    return file_get_contents('test.pdf');
  
  }
  ?&gt;
  </code></pre>
  
  <p>Hower, when the worker ends, I do not get enything in the client. If I use jobs instead of task I can get the results (i.e. the pdf file).
  Why?</p>