3

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

print gearman_version() . "\n";

抛出 php 警告

PHP 警告:模块 'gearman' 已加载到第 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 错误 [2]: GearmanClient::doBackground(): send_packet(GEARMAN_COULD_NOT_CONNECT) 发送服务器选项包失败 -> libgearman/connection.cc:430

4

2 回答 2

2

你能试试这个吗

 $gmworker->addServer('127.0.0.1','4730');
于 2013-09-05T12:56:04.933 回答
1

在命令提示符下键入 php --ini 以查看您的 PHP CLI 使用的 php.ini。确保在那个 php.ini 中启用了 Gearman。src Gearman,php 扩展问题:在 .. 中找不到类“GearmanWorker”,使用终端但在浏览器上工作

于 2013-09-06T03:45:35.963 回答