我正在使用Ubuntu Natty和PHP 5.3.5以及PECL Gearman 0.8.0。这是版本信息:
PHP 5.3.5-1ubuntu7.3 with Suhosin-Patch (cli) (built: Oct 13 2011 22:20:48)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with the ionCube PHP Loader v4.0.10, Copyright (c) 2002-2011, by ionCube Ltd., and
with Zend Guard Loader v3.3, Copyright (c) 1998-2010, by Zend Technologies
with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH
尝试通过命令行运行Gearman客户端时,我遇到了分段错误(我已经让我的工作人员正在运行)。
这是我在命令行上得到的内容:
root@Local:~/sandbox# php php_gearman_client.php
Sending job
Segmentation fault
这是我的工作人员代码:
<?php
echo "Starting\n";
# Create our worker object.
$gmworker= new GearmanWorker();
# Add default server (localhost).
$gmworker->addServer();
# Register function "reverse" with the server. Change the worker function to
# "reverse_fn_fast" for a faster worker with no output.
$gmworker->addFunction("reverse", "reverse_fn");
print "Waiting for job...\n";
while($gmworker->work())
{
if ($gmworker->returnCode() != GEARMAN_SUCCESS)
{
echo "return_code: " . $gmworker->returnCode() . "\n";
break;
}
}
function reverse_fn($job)
{
echo "Received job: " . $job->handle() . "\n";
$workload = $job->workload();
$workload_size = $job->workloadSize();
echo "Workload: $workload ($workload_size)\n";
# This status loop is not needed, just showing how it works
for ($x= 0; $x < $workload_size; $x++)
{
echo "Sending status: " . ($x + 1) . "/$workload_size complete\n";
$job->sendStatus($x, $workload_size);
sleep(1);
}
$result= strrev($workload);
echo "Result: $result\n";
# Return what we want to send back to the client.
return $result;
}
# A much simpler and less verbose version of the above function would be:
function reverse_fn_fast($job)
{
return strrev($job->workload());
}
?>
这是我的客户代码:
<?php
# Create our client object.
$gmclient= new GearmanClient();
# Add default server (localhost).
$gmclient->addServer();
echo "Sending job\n";
# Send reverse job
do
{
$result = $gmclient->do("reverse", "Hello!");
# Check for various return packets and errors.
switch($gmclient->returnCode())
{
case GEARMAN_WORK_DATA:
echo "Data: $result\n";
break;
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:
break;
default:
echo "RET: " . $gmclient->returnCode() . "\n";
exit;
}
}
while($gmclient->returnCode() != GEARMAN_SUCCESS);
?>
修改
看来分段错误是由Imagick引起的。所以我做了以下处理这个问题。
dpkg --purge --force-all php5-imagick
。我在设置PHP时安装了这个/etc/init.d/gearman-job-server stop && /etc/init.d/gearman-job-server
现在一切似乎都正常。
答案 0 :(得分:2)
因为它是分段错误,这意味着您的安装出了问题。运行dmesg
以查看更多详细信息,某些可能被禁用的php扩展可能存在问题。
答案 1 :(得分:2)
我也遇到了这个问题。 这是我采取的措施(完全解决它),以及观察错误的步骤。
运行Gearman Worker导致:
分段错误
从shell运行dmesg
,我发现它出现了。
[2423402.716386] php [21232]:段落错误30 ip b66d0321 sp bfc704c0 libuuid.so.1.3.0中的错误6 [b66cf000 + 3000]
用Google搜索libuuid.so,很明显,Imagick使用uuid_create()
作为图片UUID。
http://usrportage.de/archives/922-PHP-segfaulting-with-pecluuid-and-peclimagick.html
我确保Imagick扩展在我的所有PHP扩展中最后被初始化。 所以以前我在
的第一行 /etc/php5/conf.d/extensions.ini
档案imagick.so
我所做的是创建了一个名为imagick.ini
的文件,其内容为
imagick.so
因为扩展按字母顺序加载(如果您通过命令行运行Worker),加载imagick last可确保首先加载所有相关扩展。在这种情况下libuuid。