Gearman: Sending data from a background worker to the client

梦想与她 提交于 2019-11-28 08:12:58

问题


Is it possible to send back data from a gearman worker that runs in the background (with PHP)?

I know that I can pass a status (numerator/denominator) to the client but I need to "return" data.

The background is that I need to call workers on different servers and if they don't respond, the main script should continue. So I think I have to run the workers in the background. But I need some data from them.

UPDATE: It seems not to be possible. I think I have either to store the data in a shared database or to write it from the remote server to the local server or to read it from the remote server or to make something like this:

shell_exec('gearman -f getdata-192-168-200-1 > /my/path/ 2>&1 & echo $!');

回答1:


I think you can pass the data from the worker to client using the following function

GearmanJob::sendData($result);

By giving your data in $result variable and also you can handle this data in the client by using the function

GearmanClient::setDataCallback("task_data");

function task_data($task)
{
    echo "DATA: " . $task->data() . "\n";
}

You can get bit more information

http://www.php.net/manual/en/gearmanclient.setdatacallback.php



来源:https://stackoverflow.com/questions/7982450/gearman-sending-data-from-a-background-worker-to-the-client

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!