Gearman:将数据从后台工作者发送到客户端 [英] Gearman: Sending data from a background worker to the client

查看:86
本文介绍了Gearman:将数据从后台工作者发送到客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从后台运行的Gearman Worker(使用PHP)发回数据?

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

推荐答案

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

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

GearmanJob::sendData($result);

通过在$ 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";
}

您可以获得更多信息

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

这篇关于Gearman:将数据从后台工作者发送到客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆