我使用ubuntu 12.04 64位,PHP 5.3.10,gearman 1.1.5在我的本地系统上运行。 以下代码
print gearman_version() . "\n";
抛出php警告
PHP警告:模块'gearman'已在第0行的Unknown中加载
我还使用
构建了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";
}
} ?&GT;
和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;
}
}
&GT;
跑步工人 php job_entry.php workeradmin 等待工作...... 运行客户端 php job_entry.php admin arg1 这给了我错误
PHP错误[2]:GearmanClient :: doBackground():send_packet(GEARMAN_COULD_NOT_CONNECT)无法发送服务器选项数据包 - &gt; libgearman / connection.cc:430
答案 0 :(得分:2)
$gmworker->addServer('127.0.0.1','4730');
答案 1 :(得分:1)
在命令提示符下键入php --ini,以查看PHP CLI使用的php.ini。确保在php.ini中启用Gearman。 src Gearman , php extension problem : Class 'GearmanWorker' not found in .. using terminal but works on browser