gpt4 book ai didi

php - 从命令行运行 Gearman PHP 的段错误

转载 作者:可可西里 更新时间:2023-10-31 23:09:17 25 4
gpt4 key购买 nike

我将 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 客户端时遇到段错误(我已经让我的 worker 运行了)。

这是我在命令行上得到的:

root@Local:~/sandbox# php php_gearman_client.php
Sending job
Segmentation fault

这是我的 worker 代码:

<?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 引起的。所以我做了以下事情来处理这个问题。

  1. 删除 imagick dpkg --purge --force-all php5-imagick。我在设置 PHP 时已经安装了它
  2. 重新启动 PHP(这可能会因您安装 php 的方式而异)
  3. 重新启动 Gearman 作业服务器 /etc/init.d/gearman-job-server stop &&/etc/init.d/gearman-job-server

现在似乎一切正常。

最佳答案

因为段错误意味着您的安装有问题。运行 dmesg 以查看更多详细信息,某些可能被禁用的 php 扩展可能存在问题。

关于php - 从命令行运行 Gearman PHP 的段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8281489/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com