Question

I have the Gearman Job server where I am planning on creating the workers and do all the heavy lifting. The Gearman Job Server is called from an application server by a PHP script (already installed the gearman client on it).

Tested if the Gearman is working on the Job Server and received the following response:

ubuntu@ip XXXXXXX:~$ ps -e|grep gearman
24255 ?        00:00:00 gearmand    

And I also tested on my application server if the gearman is working by doing :

<?php
print gearman_version() . "\n";
?>

Which printed the gearman version so its working.

Now I have a client which makes the call to Job Server. But I am having difficulty finding where to put the PHP workers, link them to Gearman so it know which worker to execute when client makes a call.

Any help is much appreciated. Thanks

Was it helpful?

Solution

Gearman Workers need to be started separately, so it doesn't really matter where you put them. After you have written the worker code, just start the script from the terminal using

php /path/to/worker/gearman-worker.php

As the script starts, it will register itself with the given server and pick-up any jobs that might be available.

You can read about the Gearman worker here, but notice the important part is the server registration

$worker -> addServer();

Here, calling the function without any arguments will register the worker to a Gearman server running on localhost, but you can make it register to any server on any port by setting these arguments (as specified in the link above).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top