SlideShare una empresa de Scribd logo
1 de 19
Nemanja Krivokapić

Software Engineer @ PSTech
@NemanjaKr | LinkedIn

PHP &
Gearman
All you need to build large
scale web application
What is Gearman?
 Generic

Application Framework
 Job Server
 Client / Worker API
 Multi-platform and multi-language API
support
 Support priorities
How does it work?
Multi-server configuration
Jobs vs. Tasks
 Matter

of perspective
 Client delegates task to the server
 Job server delegates jobs to the workers
Supported platforms and
languages
 Platforms:

Unix/Windows
 Languages supported:






PHP
Java
C/C++
NodeJS, Python, Go, Lisp...
Gearman server installation
tips
 Don’t

use Ubuntu package for gearman
server (outdated and doesn’t work with
current PHP PECL extension)
 Build it from source:
https://launchpad.net/gearmand
 Run: gearmand --deamon
Server configuration
 All

config params are supplied through
command line
 Important ones:







--port=XXX (default 4730)
--deamon
--job-retries (default NO LIMIT!)
--queue-type (default builtin, not persistent)
--listen (default INADDR_ANY)

 Use

--help
PHP Gearman
implementation
Yeah – this is cool but HOW CAN I USE IT?
Little bit of shell 
 Prerequisite:

libgearman (if built from source –
already included)
 PEAR (apt-get install php-pear)
 PECL (pear install pecl)*
 pecl install gearman
 Tell PHP to use gearman client/worker API extension
( extension=gearman.so in php.ini)

* For proxy: pear config http_proxy http://
Provided classes
 GearmanClient
 GearmanTask
 GearmanWorker
 GearmanJob
 GearmanException
GearmanClient
 Used

for communication with Job Server
from your application
 Foreground jobs (doHigh, doNormal,
doLow)
 Background jobs (doHighBackground,
doBackground, doLowBackground)
 Tasks (replace do* with addTask*)
 addTask* returns GearmanTask object,
do* returns string!
GearmanWorker
 We

use it to connect our worker script to
Job Server and wait for job

 addFunction(string

$function_name
, callable $function)
 work()
 Callable provided will receive an
GearmanJob object as argument
Running tasks in parallel
 You

can stack as many tasks using
addTask method of GearmanClient.
 They will all be executed in parallel when
you call runTasks (if there’s enough
workers available)
 Notice: Using do* methods will execute
the task immediately
Client callbacks for workers
events
 When

running foreground tasks you can register
callbacks using methods of GearmanClient using
methods:







setCompleteCallback,
setCreatedCallback,
setDataCallback,
setExceptionCallback,
setFailCallback

 They

all take single argument – callable object
which will receive GearmanTask object as an
argument.
SupervisorD – keep it running
 PHP

worker script will wait for job, do it and die.
 Supervisord – Process Control System*
 apt-get install supervisor
 Create configuration file in
/etc/supervisor/supervisord.conf
 sudo service supervisor

* Project homepage: http://supervisord.org/
SupervisorD alternative
 GearmanManager
 Easier

to setup
 PHP wrapper around GearmanWorker
 https://github.com/brianlmoon/Gearman
Manager
Relevant links







PHP Examples:
http://www.php.net/manual/en/gearman.examples.
php
Gearman Job Server documentation:
http://gearman.org/documentation/
Cool tutorials to get started with Gearman on
Ubuntu:
http://blog.andyburton.co.uk/index.php/201212/compiling-gearman-with-mysql-persistent-storageon-ubuntu-12-04-precise/
http://blog.andyburton.co.uk/index.php/201212/gearman-0-41-with-mysql-persistent-storage-andphp-pecl-0-8-3-with-gearmanmanager-on-ubuntu12-04/
Questions?

The End 

Más contenido relacionado

La actualidad más candente

Simple cache architecture
Simple cache architectureSimple cache architecture
Simple cache architecture
DaeMyung Kang
 
The ten commandments for an Agile Developer
The ten commandments for an Agile DeveloperThe ten commandments for an Agile Developer
The ten commandments for an Agile Developer
Sowmya Karmali
 

La actualidad más candente (20)

Background processing with Resque
Background processing with ResqueBackground processing with Resque
Background processing with Resque
 
Wrapping java in awesomeness aka condensator
Wrapping java in awesomeness aka condensatorWrapping java in awesomeness aka condensator
Wrapping java in awesomeness aka condensator
 
ES6 ECMA2015
ES6 ECMA2015ES6 ECMA2015
ES6 ECMA2015
 
Getting Started with Capistrano
Getting Started with CapistranoGetting Started with Capistrano
Getting Started with Capistrano
 
Capistrano
CapistranoCapistrano
Capistrano
 
Simple cache architecture
Simple cache architectureSimple cache architecture
Simple cache architecture
 
Intro to MQ
Intro to MQIntro to MQ
Intro to MQ
 
Wake Up
Wake UpWake Up
Wake Up
 
Capistrano
CapistranoCapistrano
Capistrano
 
The ten commandments for an Agile Developer
The ten commandments for an Agile DeveloperThe ten commandments for an Agile Developer
The ten commandments for an Agile Developer
 
Communication in Python and the C10k problem
Communication in Python and the C10k problemCommunication in Python and the C10k problem
Communication in Python and the C10k problem
 
Async/Await: TPL & Message Pumps
Async/Await: TPL & Message Pumps Async/Await: TPL & Message Pumps
Async/Await: TPL & Message Pumps
 
Async/Await Best Practices
Async/Await Best PracticesAsync/Await Best Practices
Async/Await Best Practices
 
Deploying Rails Apps with Capistrano
Deploying Rails Apps with CapistranoDeploying Rails Apps with Capistrano
Deploying Rails Apps with Capistrano
 
Scala Future & Promises
Scala Future & PromisesScala Future & Promises
Scala Future & Promises
 
Effective java item 80 and 81
Effective java   item 80 and 81Effective java   item 80 and 81
Effective java item 80 and 81
 
Welcome Azure Functions 2. 0
Welcome Azure Functions 2. 0Welcome Azure Functions 2. 0
Welcome Azure Functions 2. 0
 
Enable IPv6 on Route53 AWS ELB, docker and node App
Enable IPv6 on Route53 AWS ELB, docker and  node AppEnable IPv6 on Route53 AWS ELB, docker and  node App
Enable IPv6 on Route53 AWS ELB, docker and node App
 
Ruby C10K: High Performance Networking - RubyKaigi '09
Ruby C10K: High Performance Networking - RubyKaigi '09Ruby C10K: High Performance Networking - RubyKaigi '09
Ruby C10K: High Performance Networking - RubyKaigi '09
 
Capistrano, Puppet, and Chef
Capistrano, Puppet, and ChefCapistrano, Puppet, and Chef
Capistrano, Puppet, and Chef
 

Destacado

Keeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro frameworkKeeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro framework
Jeremy Kendall
 
CV Vlas Ion(1)(1)
CV Vlas Ion(1)(1)CV Vlas Ion(1)(1)
CV Vlas Ion(1)(1)
Vlas Ion
 
CV Sabina Serbu_ro
CV Sabina Serbu_roCV Sabina Serbu_ro
CV Sabina Serbu_ro
Sabina Serbu
 
CV Sorina Martin europass engleza
CV Sorina Martin europass englezaCV Sorina Martin europass engleza
CV Sorina Martin europass engleza
Sorina Martin
 

Destacado (18)

Gearman and CodeIgniter
Gearman and CodeIgniterGearman and CodeIgniter
Gearman and CodeIgniter
 
Gearman
GearmanGearman
Gearman
 
Gearman and asynchronous processing in PHP applications
Gearman and asynchronous processing in PHP applicationsGearman and asynchronous processing in PHP applications
Gearman and asynchronous processing in PHP applications
 
Enchanted Objects: The next wave of the web
Enchanted Objects: The next wave of the webEnchanted Objects: The next wave of the web
Enchanted Objects: The next wave of the web
 
Keeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro frameworkKeeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro framework
 
Mihai_Nuta
Mihai_NutaMihai_Nuta
Mihai_Nuta
 
CV Vlas Ion(1)(1)
CV Vlas Ion(1)(1)CV Vlas Ion(1)(1)
CV Vlas Ion(1)(1)
 
CV Adina Neagu.
CV Adina Neagu.CV Adina Neagu.
CV Adina Neagu.
 
CV_Bazac_Costea_Laurentiu
CV_Bazac_Costea_LaurentiuCV_Bazac_Costea_Laurentiu
CV_Bazac_Costea_Laurentiu
 
Simona Lazar
Simona LazarSimona Lazar
Simona Lazar
 
Cv grasu nicoleta_ro
Cv grasu nicoleta_roCv grasu nicoleta_ro
Cv grasu nicoleta_ro
 
CV Sabina Serbu_ro
CV Sabina Serbu_roCV Sabina Serbu_ro
CV Sabina Serbu_ro
 
Cv Oana Taban Fondator
Cv Oana Taban FondatorCv Oana Taban Fondator
Cv Oana Taban Fondator
 
CV - Dimitriu Dragoș
CV - Dimitriu DragoșCV - Dimitriu Dragoș
CV - Dimitriu Dragoș
 
Cv andreea arion
Cv andreea arionCv andreea arion
Cv andreea arion
 
CV Denisa Musa 2016 English
CV Denisa Musa 2016 EnglishCV Denisa Musa 2016 English
CV Denisa Musa 2016 English
 
CV Nicoleta Cioroaba
CV Nicoleta CioroabaCV Nicoleta Cioroaba
CV Nicoleta Cioroaba
 
CV Sorina Martin europass engleza
CV Sorina Martin europass englezaCV Sorina Martin europass engleza
CV Sorina Martin europass engleza
 

Similar a Gearman & PHP

Gearmanpresentation 110308165409-phpapp01
Gearmanpresentation 110308165409-phpapp01Gearmanpresentation 110308165409-phpapp01
Gearmanpresentation 110308165409-phpapp01
longtuan
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
Ben Lin
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
Alex Su
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code
維佋 唐
 

Similar a Gearman & PHP (20)

Gearman - Job Queue
Gearman - Job QueueGearman - Job Queue
Gearman - Job Queue
 
Distributed Applications with Perl & Gearman
Distributed Applications with Perl & GearmanDistributed Applications with Perl & Gearman
Distributed Applications with Perl & Gearman
 
Gearmanpresentation 110308165409-phpapp01
Gearmanpresentation 110308165409-phpapp01Gearmanpresentation 110308165409-phpapp01
Gearmanpresentation 110308165409-phpapp01
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with Ansible
 
OSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshopOSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshop
 
React loadable
React loadableReact loadable
React loadable
 
AMIMOTO: WordPress + Amazon Web Services Hands-on PARIS
AMIMOTO: WordPress + Amazon Web Services Hands-on PARISAMIMOTO: WordPress + Amazon Web Services Hands-on PARIS
AMIMOTO: WordPress + Amazon Web Services Hands-on PARIS
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidence
 
Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015Rhebok, High Performance Rack Handler / Rubykaigi 2015
Rhebok, High Performance Rack Handler / Rubykaigi 2015
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
Building Web Apps with Express
Building Web Apps with ExpressBuilding Web Apps with Express
Building Web Apps with Express
 
Serverless in-action
Serverless in-actionServerless in-action
Serverless in-action
 
Distributed Queue System using Gearman
Distributed Queue System using GearmanDistributed Queue System using Gearman
Distributed Queue System using Gearman
 
Appium troubleshooting
Appium troubleshootingAppium troubleshooting
Appium troubleshooting
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code
 
Node js
Node jsNode js
Node js
 
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
 
Red5 - PHUG Workshops
Red5 - PHUG WorkshopsRed5 - PHUG Workshops
Red5 - PHUG Workshops
 
Local SQLite Database with Node for beginners
Local SQLite Database with Node for beginnersLocal SQLite Database with Node for beginners
Local SQLite Database with Node for beginners
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 

Gearman & PHP

  • 1. Nemanja Krivokapić Software Engineer @ PSTech @NemanjaKr | LinkedIn PHP & Gearman All you need to build large scale web application
  • 2. What is Gearman?  Generic Application Framework  Job Server  Client / Worker API  Multi-platform and multi-language API support  Support priorities
  • 3. How does it work?
  • 5. Jobs vs. Tasks  Matter of perspective  Client delegates task to the server  Job server delegates jobs to the workers
  • 6. Supported platforms and languages  Platforms: Unix/Windows  Languages supported:     PHP Java C/C++ NodeJS, Python, Go, Lisp...
  • 7. Gearman server installation tips  Don’t use Ubuntu package for gearman server (outdated and doesn’t work with current PHP PECL extension)  Build it from source: https://launchpad.net/gearmand  Run: gearmand --deamon
  • 8. Server configuration  All config params are supplied through command line  Important ones:      --port=XXX (default 4730) --deamon --job-retries (default NO LIMIT!) --queue-type (default builtin, not persistent) --listen (default INADDR_ANY)  Use --help
  • 9. PHP Gearman implementation Yeah – this is cool but HOW CAN I USE IT?
  • 10. Little bit of shell   Prerequisite: libgearman (if built from source – already included)  PEAR (apt-get install php-pear)  PECL (pear install pecl)*  pecl install gearman  Tell PHP to use gearman client/worker API extension ( extension=gearman.so in php.ini) * For proxy: pear config http_proxy http://
  • 11. Provided classes  GearmanClient  GearmanTask  GearmanWorker  GearmanJob  GearmanException
  • 12. GearmanClient  Used for communication with Job Server from your application  Foreground jobs (doHigh, doNormal, doLow)  Background jobs (doHighBackground, doBackground, doLowBackground)  Tasks (replace do* with addTask*)  addTask* returns GearmanTask object, do* returns string!
  • 13. GearmanWorker  We use it to connect our worker script to Job Server and wait for job  addFunction(string $function_name , callable $function)  work()  Callable provided will receive an GearmanJob object as argument
  • 14. Running tasks in parallel  You can stack as many tasks using addTask method of GearmanClient.  They will all be executed in parallel when you call runTasks (if there’s enough workers available)  Notice: Using do* methods will execute the task immediately
  • 15. Client callbacks for workers events  When running foreground tasks you can register callbacks using methods of GearmanClient using methods:      setCompleteCallback, setCreatedCallback, setDataCallback, setExceptionCallback, setFailCallback  They all take single argument – callable object which will receive GearmanTask object as an argument.
  • 16. SupervisorD – keep it running  PHP worker script will wait for job, do it and die.  Supervisord – Process Control System*  apt-get install supervisor  Create configuration file in /etc/supervisor/supervisord.conf  sudo service supervisor * Project homepage: http://supervisord.org/
  • 17. SupervisorD alternative  GearmanManager  Easier to setup  PHP wrapper around GearmanWorker  https://github.com/brianlmoon/Gearman Manager
  • 18. Relevant links     PHP Examples: http://www.php.net/manual/en/gearman.examples. php Gearman Job Server documentation: http://gearman.org/documentation/ Cool tutorials to get started with Gearman on Ubuntu: http://blog.andyburton.co.uk/index.php/201212/compiling-gearman-with-mysql-persistent-storageon-ubuntu-12-04-precise/ http://blog.andyburton.co.uk/index.php/201212/gearman-0-41-with-mysql-persistent-storage-andphp-pecl-0-8-3-with-gearmanmanager-on-ubuntu12-04/