I am trying to make some job in background and write result to file result from complete callback, but its only work for addTask (not in background) and not for addTaskBackground
have somebody any ideas?
thanks for help!
$client = new GearmanClient();
$client->addServer('localhost');
$client->setCompleteCallback("complete");
$client->addTaskBackground('upload', 'http://youtube.com/watch?v=o3mP3mJDL2k', null, 1);
$client->addTaskBackground('upload', 'http://www.youtube.com/watch?v=SgAVnlnf8w0', null, 2);
/* in these case complete callback works
$client->addTask('upload', 'http://youtube.com/watch?v=o3mP3mJDL2k');
$client->addTask('upload', 'http://www.youtube.com/watch?v=SgAVnlnf8w0');
*/
$client->runTasks();
function complete($task){
file_put_contents('/home/vonica/public_html/test/tmp/1.txt', $task->unique() . ", " . $task->data() . "\n", FILE_APPEND);
}
$worker = new GearmanWorker();
$worker->addServer('localhost');
$worker->addFunction('upload', 'uploader');
while($worker->work()){
if ($worker->returnCode() != GEARMAN_SUCCESS) {
echo "ret code: " . $worker->returnCode() . "\n";
break;
}
};
function uploader($job){
$content = $job->workload();
exec ('echo $( youtube-dl -f worst "'.$content.'")');
return $content;
}