1. Install gearman, server and client:
$ sudo apt-get install gearman-job-server
2. Creat gearmand log file:
$ mkdir ~/log/gearmand
$ touch ~/log/gearmand/gearmand.log
$ cd ~/log/gearmand
3. Start gearman server on localhost (127.0.0.1), port 4730
$ gearmand --log-file gearmand.log --listen 127.0.0.1 --port=4730 --verbose=INFO
4. Register gearman worker (with funciton name wwcc):
$ gearman -w -h 127.0.0.1 -p 4730 -f wwcc -- wc -l
5. Send data/request from a gearman client:
$ gearman -h 127.0.0.1 -p 4730 -f wwcc < /etc/passwd
$ gearman -h 127.0.0.1 -p 4730 -f wwcc "hello world"
6. The stdout on terminal shows the result, something like:
48 78 2409
0 2 11
For default localhost:4730, step 3 can be simplified to, (in addtion, running in background):
$gearmand -d -l gearmand.log
http://gearman.org/getting_started
http://stackoverflow.com/questions/6995202/problem-with-gearman-gearman-could-not-connect
http://stackoverflow.com/questions/14526086/gearman-issues-php-cli
$man gearman
$man gearmand
$gearmand -h
$man gearadmin
Related error messages:
gearmand: Could not open log file "/usr/local/var/log/gearmand.log", from "/home", switching to stderr. (Permission denied)
This means the access to gearmand.log file is limited (owned by root?). Creating a new log file solves this problem (step 2 above).
gearman: gearman_client_run_tasks : flush(GEARMAN_COULD_NOT_CONNECT) localhost:0 -> libgearman/connection.cc:672
The gearmand server is not running, or binds to a different address:port than requested. (step 3 above)
gearmand: unknown option -v
The -v option is not suppored in new versions. use: --verbose=INFO (step 3 above)
ERROR 2013-04-13 22:15:55.000000 [ main ] Timeout occured when calling bind() for 0.0.0.0:4730 -> libgearman-server/gearmand.cc:616
The listen to address is bad. Specify localhost by -h 127.0.0.1 (step3,4,5 above)
gearmand: error while loading shared libraries: libboost_program_options.so.1.48.0: cannot open shared object file: No such file or directory
$sudo apt-get install libboost-program-options1.48.0
After some updates, the old boost lib was autoremoved. Just reinstall it and problem solved.