1. An application framework
to distribute work
Presenter: Biswajit Maji, Mindfire Solutions
Date: 9/04/2014
Add it to your project
2. Presenter: Biswajit Maji, Mindfire Solutions
OCP – Oracle certified
professional developer
About Me
Skills : Mysql, php, jQuery, html,
VCS(svn, git), Webservices, Linux
Connect Me:
Facebook: https://www.facebook.com/biswajitmaji.tech
LinkedIn: http://www.linkedin.com/profile/view?id=133902574
Google+: https://plus.google.com/105085556902166170611/
Contact Me:
Email: biswajitm@mindfiresolutions.com / biswajitmaji.tech@gmail.com
Skype: mfsi_biswajitm
3. Presenter: Biswajit Maji, Mindfire Solutions
AGENDA
A short description of Gearman
Some real time problem we face
Installing Gearman Server
Installing PHP API
Gearman Worker code
Gearman Client code
Few most used Gearman client methods
Demo
4. Presenter: Biswajit Maji, Mindfire Solutions
A short description of Gearman
Open source application framework
To distribute appropriate computer tasks to multiple computers
So large tasks can be done more quickly
Load balancing
Parallel and asynchronous work
Scales well
Architecture-based workload distributing
Fault tolerance using multiple server.
It is an application framework to distribute work
5. Presenter: Biswajit Maji, Mindfire Solutions
Some real time problem we face
Sending bulk email
Image resizing
Watermarking
Jobs using other language
http://opentechlovers.wordpress.com/2013/12/17/ba
ckground-processes-how-dangerous-it-could-be/
Problem we face in real time
6. Presenter: Biswajit Maji, Mindfire Solutions
Installing Gearman Server
in linux box
As usual
sudo apt-get install gearman-job-server
Start gearman server:
sudo gearmand -d
The -d (--daemon) option causes the server to detach
from the shell and run in the background.
Want to know all available options:
Gearmand -h [ --help ]
Install gearman tool
sudo apt-get install gearman-tools
All available option
gearman -h
7. Presenter: Biswajit Maji, Mindfire Solutions
Installing php api
If want to use pecl for installing gearman
sudo apt-get install php-pear
It may not be needed if following other way to install gearman php api.
apt-get install libgearman-dev // used to configure internally
apt-get install php5-dev // this is needed for phpize
Install api
pecl install gearman
Finally add this in php.ini file
extension="gearman.so"
8. Presenter: Biswajit Maji, Mindfire Solutions
Gearman Worker code
# Create our worker object.
$gmworker= new GearmanWorker();
# Add default server (localhost).
$gmworker->addServer();
# Register function "reverse" with the server.
$gmworker->addFunction("reverse", "reverse_fn");
10. Presenter: Biswajit Maji, Mindfire Solutions
Few most used Gearman Client methods
addServer("10.0.0.2", 7003)
addServers("10.0.0.1,10.0.0.2:7003")
$client->addTask(string $function_name , string $workload [, mixed
&$context [, string $unique ]]);
$client->runTasks();
$client->addTaskBackground();
$client->addTaskHigh();
setCompleteCallback — Set a function to be called on task completion
setCreatedCallback — Set a callback for when a task is queued
setExceptionCallback — Set a callback for worker exceptions
setFailCallback — Set callback for job failure
setWarningCallback — Set a callback for worker warnings