我有:
- Debian 6
- nginx 1.2.6
- PHP 5.3.20-1~dotdeb.0 (fpm-fcgi) (内置: Dec 24 2012 11:53:16)
- 齿轮指令 1.1.4
- pecl gearman ext 1.1.1
我得到了两个脚本(可能是我从 php 复制的)。客户:
<?php
$gmc= new GearmanClient();
$gmc->addServer();
$gmc->setCompleteCallback("reverse_complete");
$gmc->setStatusCallback("reverse_status");
$gmc->addTask("reverse", "!dlroW olleH", null, "2");
if (!$gmc->runTasks())
{
echo "Error " . $gmc->error() . "\n";
exit;
}
echo "Done\n";
function reverse_status($task)
{
echo "Status: " . $task->unique() . ", " . $task->jobHandle() . " - " . $task->taskNumerator() .
"/" . $task->taskDenominator() . "\n";
}
function reverse_complete($task)
{
echo "Done: " . $task->unique() . ", " . $task->data() . "\n";
}
?>
和工人:
<?php
$gmworker= new GearmanWorker();
$gmworker->addServer('127.0.0.1');
$gmworker->addOptions(GEARMAN_WORKER_GRAB_UNIQ);
$gmworker->addFunction("reverse", "reverse_fn");
print "Waiting for tasks...\n";
while($gmworker->work())
{
if ($gmworker->returnCode() != GEARMAN_SUCCESS)
{
echo "return code: " . $gmworker->returnCode() . "\n";
break;
}
}
function reverse_fn($job)
{
echo "uniq: " . $job->unique() . "\n";
echo "I got job: " . $job->handle() . "\n";
$workload = $job->workload();
$workload_size = $job->workloadSize();
echo "Workload: $workload ($workload_size)\n";
for ($x= 0; $x < $workload_size; $x++)
{
echo "Sending status: " . ($x + 1) . "/$workload_size is done\n";
$job->sendStatus($x+1, $workload_size);
$job->sendData(substr($workload, $x, 1));
sleep(1);
}
$result= strrev($workload);
echo "The result: $result\n";
return $result;
}
?>
我通过“gearmand -d”运行 gearmand。我通过“php worker.php”启动工作者。
我从浏览器打开客户端脚本,任务转到服务器,一切正常。但是当我从 2+ 个浏览器选项卡打开相同的脚本时,gearmand 会收到 2+ 个具有相同唯一 ID 的类似任务。
当我添加后台任务或使用 doBackground 方法或在 CLI 模式下时,不会发生这种情况。两种以上不同的浏览器也不会发生这种情况。
我尝试了不同的客户端和服务器版本。同样的事情也会发生。
我完全被困住了。谢谢您的帮助。