gpt4 book ai didi

php - Gearman PHP, sendComplete 没有效果

转载 作者:搜寻专家 更新时间:2023-10-31 21:44:02 26 4
gpt4 key购买 nike

已成功将 Gearman 连接到现有的 PHP 项目。使用 supervisord 来确保 worker 正在运行,它产生了相当不错的效果!

但是,我有一个严重的问题,因为“setCompleteCallback”根本不起作用。

像这样拆分:

客户端

$client = new GearmanClient();
$client->addServer();
$client->setCompleteCallback(
array( 'LDPE_Service_AWSConnect_Transfer_Target', 'transferComplete' ) );

// push core to S3 bucket
$target = new LDPE_Service_AWSConnect_Transfer_Target( $transaction->id,
"/usr/local/include/LDP/", LDPE_Service_S3::BUCKET_CORE );

// push S3 bucket to instances
foreach( $aws_target_list as $dns )
{
$target->addChildRequest(
new LDPE_Service_AWSConnect_Transfer_Target( $transaction->id,
null, LDPE_Service_S3::BUCKET_CORE, $dns )
);
}


$client->addTaskBackground( 'transferStart', serialize( $target ) );
$client->runTasks();

worker

(基本上引导 Zend Framework 环境,并加载 exec 函数)

include 'bootstrap.php';    

ini_set('memory_limit', -1);


$worker = new GearmanWorker();
$worker->addServer();

$worker->addFunction( 'transferStart', array(
'LDPE_Service_AWSConnect_Transfer_Target', 'transferStart' ) );

while ($worker->work())
{
switch( $worker->returnCode() )
{
case GEARMAN_SUCCESS:
break;

default:
echo "ERROR RET: " . $worker->returnCode() . "\n";
exit;
}
}

最后,这是包含所有繁重工作的 LDPE_Service_AWSConnect_Transfer_Target 类。我已经删除了所有逻辑,它根本不会触发。

实现方法

class LDPE_Service_AWSConnect_Transfer_Target {

public static function transferStart( GearmanJob $job )
{

$workload = $job->workload();
$target = unserialize( $workload );

echo "transferStart/begin [ " .
$target->getShortRepresentation() . " ]\n";
// perform a series of actions

echo "transferStart/complete [ " .
$target->getShortRepresentation() . " ]\n";
return serialize( $target );
}


public static function transferComplete( GearmanTask $task )
{
echo "transferComplete/begin\n";

$workload = $task->data();
$parent_target = unserialize( $workload );


echo "transferComplete/complete\n";
}
}

为了清楚起见,“transferStart/begin”和“transferStart/complete”字符串被正确打印到日志中,但是,transferComplete/begin 从未被触发。怎么回事?

谢谢!亚历克斯


似乎在后台模式下运行时回调不会触发..

最佳答案

尝试在调用流程函数后设置回调

$client->addTaskBackground('my_task', 'payload');
$client->setCompleteCallback('complete');
$client->runTasks();

关于php - Gearman PHP, sendComplete 没有效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6575658/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com