Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

SitePoint PHP Blog:
Introduction to Gearman - Multitasking in PHP
Nov 04, 2013 @ 19:23:11

The SitePoint PHP blog has posted an introductory tutorial showing you how to use Gearman in PHP to handle multitasking outside of the normal script execution. Gearman is an external job server that lets you schedule scripts and tasks for execution.

How many times have you developed a web application that had some functionality which would benefit from running an external program or even forking a separate process? This is not something you generally like to do from your web app because you want to make it run as fast and efficient as possible, while keeping the site functional for end users. So how do we get a fast but full-featured application that can process more than the average app we're used to?

They start by introducing you to Gearman - the server side - and how it works to handle a large amount of jobs quickly (50 thousand per second according to the article). They give the example of resizing images uploaded by users to illustrate. Next up is the installation - first Gearman then on to the PHP side, installing the PECL extension and adding it to the php.ini configuration. An example script is also provided showing how to create a new connection to Gearman and configure the callbacks for handling status changes. They also include adding two kinds of tasks - a normal one and a low priority one.

tagged: tutorial gearman introduction install configure process task

Link: http://www.sitepoint.com/introduction-gearman-multi-tasking-php/

Hasin Hayder:
Installing gearmand, libgearman & pecl gearman for php from source in Debian 6 & 7
Oct 31, 2013 @ 16:55:51

Hasin Hayder has posted a complete guide to getting Gearman and PHP playing nicely together. The guide gives you a step by step (and command by command) list to follow so you don't have the same pains he did trying to get it working.

I had a pretty rough evening today. No, not because the waiter forgot to add sugar in my tea, but because it was so boring to go through the trial and errors of installing gearman daemon and pecl gearman extension for php.

He walks though the whole process, starting with the failures, that he took getting it installed. Unfortunately it wasn't just as easy as installing a package and using PECL to drop in the extension. There was other software packages that needed to be installed as well and were a bit harder to figure out - libboost, gperf, libevent, uuid-dev and libcloog-ppl-dev. With these installed, the PECL install command was finally able to build and he got the shared module he needed.

tagged: install guide gearman gearmand pecl debian source extension

Link: http://hasin.me/2013/10/30/installing-gearmand-libgearman-and-pecl-gearman-from-source/

Lorna Mitchell:
PHP and Gearman: Unable to connect after upgrade
Feb 28, 2013 @ 18:55:48

Lorna Mitchell has shared some advice about correcting an issue with PHP and Gearman after she did an upgrade via PECL.

I upgraded PHP and related pecl modules on my development machine today, and ran into a problem with Gearman. Actually I ran into more than one! Firstly the challenge of getting the newest pecl version working with a gearman version. Then an error where my existing PHP application couldn't connect to gearman after upgrade.

Running on Ubuntu, she found this tutorial helpful in getting Gearman back into a working state and installed (version 1.1.1). The "unable to connect" error turned out to be a change in how the Gearman connection needed to be made - the addition of a port to the connection string made things work again.

tagged: gearman connection issue pecl ubuntu port

Link:

Community News:
Atlanta PHP November 2012 Meeting - The Magical World of Gearman
Oct 18, 2012 @ 16:55:45

The Atlanta PHP User Group has announced their November meeting - Brian Moon talking about "The Magical World of Gearman":

Gearman is a simple and robust tool for distributing asynchronous or offline work across a large number of worker boxes. Gearman will let you run a simple asynchronous task in only a few lines of code (and in many languages). This talk will focus on what Gearman is, some use cases for it, and how you can quickly start using it with PHP.

The meeting is being held at Thompson Technologies Thursday, November 1st from 7-9pm. A mini-talk from Scott Lively about PHP_CodeSniffer will also be given.

Have an upcoming user group meeting you'd like announced? let us know!

tagged: atlantaphp usergroup november meeting gearman

Link:

Vance Lucas:
Handling Exceptions in Gearman Tasks (Even Background Ones)
Aug 03, 2012 @ 13:28:25

Vance Lucas has a quick new post to his site showing you how to handle exceptions in Gearman tasks so that they can be logged correctly as a failure.

I recently had some issues with Gearman tasks throwing exceptions and killing the whole Gearman daemon. This made it nearly impossible to trace errors back to their origin, because the logged exception stack trace didn’t provide much useful information, because it just logged where it failed in Gearman. [...] The only other place to add code that will catch exceptions for all jobs run is in the GearmanWorker::addFunction method.

To solve the issue, he ends up passing in a closure that takes in the $task and wraps its execution in a try/catch to handle the exception correctly. This is then thrown to a custom exception handler and logged for future diagnosis.

tagged: gearman exception handling try catch closure

Link:

/Dev/Hell Podcast:
Episode 5 - The Hammer That Is PHP
Feb 06, 2012 @ 18:03:42

The /dev/hell podcast has released their latest episode with special guest Brian Moon (of dealnews).

In our fifth episode we speak to our first ever guest Brian Moon, ancient PHP elder of dealnews and someone who has probably forgotten more about PHP than our two hosts will ever know. [...] In this episode we talk about dealnews, how they use PHP (and how they also use it in some interesting ways), and his thoughts on issues like concurrency and evented systems. We also cover features of PHP that allowed for some major changes and approaches they used in the code base for the site.

Other technologies discussed include Gearman, Node.js, Squid and Varnish. You can listen to this latest episode either via the in-page player or by downloading the mp3 directly.

tagged: devhell podcast hammer brianmoon dealnews gearman edfinkler chrishartjes

Link:

Ralph Schindler's Blog:
Compiling Gearman (or anything) for Zend Server CE on Snow Leopard
Jan 09, 2012 @ 16:59:35

Ralph Schindler has a new post to his blog today detailing the process you'll need to compile Gearman (or just about anything) on a Zend Server CE install on Snow Leopard.

Zend Server CE for Mac (as of this writing), comes compiled as an i386 executable only. This includes the PHP binary, php library, and apache binaries that come shipped with ZSCE. While ZSCE works great out the box with all the provided extensions, you might find that you want some additional 3rd party PHP extensions compiled/linked into this stack. That's where things get a little confusing, and in this post, we’ll look at how to install the gearman extension.

He give two methods - the easy way where you can export a CFLAGS setting to compile with multiple architectures or the harder way (that works for Gearman), building static libraries. The full list of commands (and some example output) is included in the post. In the comments there's also an example of the install if you're using Macports.

tagged: gearman compile zendserverce snowleopard osx mac tutorial

Link:

Matthew Wells' Blog:
Kohana and Gearman - Practical Multitasking
Aug 30, 2011 @ 16:39:11

Matthew Wells has a new post that looks at combining Kohana and Gearman to create a system to handle large data processing without slowing down the rest of the application.

A commonly identified bottleneck arises when dealing with large, 'expensive' data. This is commonly seen when an application posts a large volume of well structured data to the API (that some process must be carried out upon), before some form of structured receipt is then returned as a request response. [...] Analysing such a request tends to show high PHP CPU usage with lower database consumption. [...] The structured nature of data exchanged via an API means that we can, relatively simply and reliably, divide the submitted data and process it simultaneously with the help of a great tool called Gearman.

He walks you through the entire process including his initial thoughts on what the system should be and how it should behave when the requests are made. He shares the code he used to implement the system - a simple worker that processes part of the request and returns the results. The command-line calls to run the worker manually for testing are also included.

tagged: multitask gearman kohana worker process api request

Link:

Dave Marshall' Blog:
Asynchronous cache priming with progress bars via Gearman, Memcache and Dojo
Apr 04, 2011 @ 15:18:20

Dave Marshall has written up a new post showing how he's used memcache, Gearman and Dojo to create an asynchronous progress bar he uses when generating large reports.

I have a (highly optimised) report that takes way too long to generate, up to around 30 seconds. [There's] too many variables to prime caches for every possible combination [and] personally, I don’t think the browsers inbuilt progress bar is enough feedback for todays web users.

He generates the data into memcache when the user requests it and uses the Gearman worker processes to handle requests for data that doesn't yet exist. The progress bar is a part of Dojo and uses the dijit.ProgressBar widget to keep checking the progress of the build. This way the user can even leave the page and come back if the process takes too long with no threat to the generating report. You can find all of his code he's used to make it happen on his github account.

tagged: gearman tutorial memcache dojo progressbar generate report

Link:

Gonzalo Ayuso's Blog:
Watermarks in our images with PHP and Gearman
Mar 07, 2011 @ 18:12:17

Gonzalo Ayuso had previously shown how to dynamically add watermarks to your images with the help of a mod_rewrite rule. One of the side effects of this is that, with a high load on your server, things can get bogged down quite quickly. His alternative? Add the watermarks to your images with Gearman workers.

In this second solution I will use a gearman worker to generate the watermarks. The benefits of gearman is the possibility of use a pool of workers. We can add/remove workers if our application scales. Those workers can be placed even at different hosts, and we can swap easily from one configuration to another.

He includes some sample scripts to illustrate the process - a Gearman client that'll call the watermarking process and a worker that takes in the image and transforms it with GD to add a new layer for the watermark.

tagged: watermark image tutorial gearman worker client

Link:


Trending Topics: