我運行在我的本地系統上,使用Ubuntu 12.04 64位,PHP 5.3.10,gearman 1.1.5。 下面的代碼gearman doBackground()不能用於php
print gearman_version() . "\n";
拋出PHP警告
PHP警告:模塊 '的Gearman' 已裝入未知在線0
而且我建警予的控制檯應用程序使用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;
}
}
?>
運行工人 PHP job_entry.php workeradmin 正在等待作業... 運行客戶端 PHP job_entry .php admin arg1 這給我錯誤
PHP錯誤[2]:GearmanClient :: doBackground():Sent_Packet的(GEARMAN_COULD_NOT_CONNECT)無法將服務器選件包 - > libgearman/connection.cc:430
什麼是解決方案 'PHP警告:模塊'gearman'已經加載在未知的行0' 這個錯誤。 –
檢查此頁http://www.somacon.com/p520.php – Mohsen