I've installed gearman on ubuntu 10.04 recently and installed it's pecl extension. Now , when I run a php file in the browser that contains :
$client = new GearmanWorker();
die(var_Dump($client));
I get object(GearmanWorker)#1 (0) { }
but when runn开发者_如何转开发ing the a real worker file in terminal (by root) , I get this:
sudo php worker.php
PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/imagick.ini on line 1 in Unknown on line 0
PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/mcrypt.ini on line 1 in Unknown on line 0
PHP Warning: Module 'pcntl' already loaded in Unknown on line 0
PHP Fatal error: Class 'GearmanWorker' not found in /home/ME/public_html/try/worker.php on line 3
The worker code :
#!/usr/bin/php
<?php $worker= new GearmanWorker();
$worker->addServer('127.0.0.1');
$worker->addFunction("reverse", "reverse_fn");
while (1) {
print "Waiting for job...\n";
$ret = $worker->work();
if ($worker->returnCode() != GEARMAN_SUCCESS)
break;
}
function reverse_fn ($job)
{
$workload = $job->workload();
echo "Received
job: " . $job->handle() . "\n";
echo "Workload: $workload\n";
$result = strrev($workload);
for ($i = 1; $i <= 10; $i ++) {
$job->status($i, 10);
sleep(1);
}
echo "Result: $result\n";
return $result;
}
Please help!
Type php --ini
at your command prompt to see which php.ini your PHP CLI uses. Make sure Gearman is enabled in that php.ini.
using locate php.ini
in my ubuntu laptop show 2 results:
/etc/php5/apache2/php.ini
/etc/php5/cli/php.ini
add both extension=gearman.so
into 2 php.ini file
then restart php and gearmand working now.
Install the gearman job server and libgearman
apt-get install gearman-job-server libgearman-dev
Install the pecl extension
apt-get install php-pear php5-dev pecl install gearman
Open the correct php.ini file and add
extension=gearman.so
at the end.
精彩评论