I am using Ubuntu Natty with PHP 5.3.5 and PECL Gearman 0.8.0 . Here is the version information:
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
I get a segmentation error when I try to start the Gearman client through the command line (I already have my worker).
Here is what I get on the command line:
root@Local :~/sandbox
Here is my working code:
<?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()); } ?>
And here is my client code:
<?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); ?>
EDIT
It seems that the segmentation error was caused by Imagick. So I decided to do the following.
- Remove imagick
dpkg --purge --force-all php5-imagick
. I installed this when I configured PHP - Restart PHP (this may vary depending on how you installed php)
- Reboot the Gearman job server
/etc/init.d/gearman-job-server stop && /etc/init.d/gearman-job-server
Everything seems to be working fine.
source share