gpt4 book ai didi

php - gearman doBackground() 不使用 php

转载 作者:搜寻专家 更新时间:2023-10-31 20:42:39 25 4
gpt4 key购买 nike

我在本地系统上运行 ubuntu 12.04 64 位、PHP 5.3.10、gearman 1.1.5。以下代码

print gearman_version() . "\n";

抛出 php 警告

PHP Warning: Module 'gearman' already loaded in Unknown on line 0

我还使用

构建了 yii 控制台应用程序 WorkerAdminCommand.php
<?php
class WorkerAdminCommand extends CConsoleCommand {

public function run() {

$gmworker = new GearmanWorker();
$gmworker->addServer(); // also tried with $gmworker->addServer('127.0.0.1:4730');
$gmworker->addFunction("getMyFunc", array($this, "getMyFunc"));
print "Waiting for job...\n";
while ($gmworker->work()) {
if ($gmworker->returnCode() != GEARMAN_SUCCESS) {
echo "return_code: " . $gmworker->returnCode() . "\n";
break;
}
}
}

public function getMyFunc($job) {
echo "start \n";
// long task
echo "\n end \n";
}

}?>

和AdminCommand.php

<?php

class AdminCommand extends CConsoleCommand {

public function run($args) {
$gmclient = new GearmanClient();
$gmclient->addServer();

echo "Sending job\n";
$data = $args[0];
$result = $gmclient->doBackground("getMyFunc", $data);

# Check for various return packets and errors.
switch ($gmclient->returnCode()) {
case GEARMAN_WORK_STATUS:
list($numerator, $denominator) = $gmclient->doStatus();
echo "Status: $numerator/$denominator complete\n";
break;
case GEARMAN_WORK_FAIL:
echo "Failed\n";
exit;
case GEARMAN_SUCCESS:
echo "Job process successfully\n";
break;
default:
echo "RET: " . $gmclient->returnCode() . "\n";
exit;

}
echo $result . PHP_EOL;
}

?>

运行 worker php job_entry.php workeradmin等待工作...运行客户端php job_entry.php admin arg1这给了我错误

PHP Error[2]: GearmanClient::doBackground(): send_packet(GEARMAN_COULD_NOT_CONNECT) Failed to send server-options packet -> libgearman/connection.cc:430

最佳答案

你能试试这个吗

 $gmworker->addServer('127.0.0.1','4730');

关于php - gearman doBackground() 不使用 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18636786/

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