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 running 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: $workloadn"; $result = strrev($workload); for ($i = 1; $i <= 10; $i ++) { $job->status($i, 10); sleep(1); } echo "Result: $resultn"; return $result; }
Please help!
Advertisement
Answer
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.