Gearman & PHP
Upcoming SlideShare
Loading in...5

Gearman & PHP



All you need to build large scale applications on distributed architecture using different programming language.

All you need to build large scale applications on distributed architecture using different programming language.



Total Views
Views on SlideShare
Embed Views



2 Embeds 2 1 1



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Gearman & PHP Gearman & PHP Presentation Transcript

  • 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? View slide
  • Multi-server configuration View slide
  • 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:  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 ( 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:
  • SupervisorD alternative  GearmanManager  Easier to setup  PHP wrapper around GearmanWorker  Manager
  • Relevant links     PHP Examples: php Gearman Job Server documentation: Cool tutorials to get started with Gearman on Ubuntu:
  • Questions? The End 