Gearman:将数据从后台工作人员发送到客户端

发布于 2024-12-13 10:27:29 字数 371 浏览 3 评论 0原文

是否可以从后台运行的 gearman 工作人员(使用 PHP)发回数据?

我知道我可以将状态(分子/分母)传递给客户端,但我需要“返回”数据。

背景是我需要调用不同服务器上的工作人员,如果他们没有响应,则主脚本应该继续。所以我想我必须在后台运行工人。但我需要他们提供一些数据。

更新: 似乎不可能。我想我必须将数据存储在共享数据库中,或者将其从远程服务器写入本地服务器,或者从远程服务器读取数据,或者进行如下操作:

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

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 $!');

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情栀口红 2024-12-20 10:27:29

我认为您可以使用以下函数将数据从工作人员传递到客户端

GearmanJob::sendData($result);

通过在 $result 变量中提供数据,您也可以使用该函数在客户端中处理这些数据

GearmanClient::setDataCallback("task_data");

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

您可以获得更多信息

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文