murshed ahmmad khan (usamurai) on May 1st, 2013
  • Sharebar

Gearman flow chart

After running a simple PHP Gearman client script, it throws the error below:

PHP Warning: GearmanClient::do(): send_packet(GEARMAN_COULD_NOT_CONNECT) Failed to send server-options packet -> libgearman/ in /home/work/public_html/site/gearman_client.php on line 14


The default host and port of Gearman is “localhost” and 4730 respectively. Normally you don’t need to mention it explicitly according to the documentation. But apart from the documentation, I had to explicitly mention it in both client and worker script to make it work.


Ref: You might also want to look into this post.

Sample Worker script: (/usr/bin/php ./gearman_worker.php)

// Register the processing function
$worker->addFunction(“process_string”, “processString”);
// Trigger the infinite loop
while ($worker->work());

print “Waiting for job…\n”;
if ($gmworker->returnCode() != GEARMAN_SUCCESS)
echo “return_code: ” . $gmworker->returnCode() . “\n”;

// The main function that processes the job
function processString($job)
// get the workload – it’s a string. use serialization to pass objects
$param = $job->workload();
return “You passed the string: {$param} \n It had: “.strlen($param).” chars \n”;

Sample Client script: (/usr/bin/php ./gearman_client.php)

// print the output of the job. first parameter is the job name, second one is the parameter
print $client->do(“process_string”, “Hello Gearman from Client!”);

# set some arbitrary application data
$data[‘foo’] = ‘bar’;

# add two tasks
$task= $gmc->addTask(“reverse”, “foo”, $data);
$task2= $gmc->addTaskLow(“reverse”, “bar”, NULL);

# run the tasks in parallel (assuming multiple workers)
if (! $gmc->runTasks())
echo “ERROR ” . $gmc->error() . “\n”;

echo “DONE\n”;


I’ll add a more complete example script later.

Hope, it’ll help someone!

murshed ahmmad khan (usamurai) on May 1st, 2013
  • Sharebar

If you have already installed Gearman Job server, now it’s time to install the PHP extension to make it usable from PHP scripts.

Gearman API

Gearman PHP Extension
The Gearman PHP extension wraps the C library installed with the Gearman C Job Server package. This provides a client and worker interface in PHP that looks much like the C interface. The PHP extension also extends the procedural interface to provide a native object oriented interface as well. This allows you to use either programming paradigm with the extension. This document will use the object oriented interface.


The Gearman PHP extension is hosted on PECL like most other extensions. Building PHP extensions assumes the PHP development package is installed (php5-dev on Ubuntu and Debian). The PHP command line interface package should also be installed for development and workers (php5-cli on Ubuntu and Debian). The tarball should be downloaded from PECL, and then to build and install run:

1. Install php-devel dependency via yum

# yum install php-devel

2. Get the latest stable build from Gearman PECL extension page. The current stable release is version 1.1.1

# wget
# tar -xzvf gearman-1.1.1.tgz
# cd gearman-1.1.1

3. Now phpize and complie it:

# phpize
# make
# make install

You will finally see something like this:

Installing shared extensions: /usr/lib64/php/modules/

4. Update PHP.INI file:

The following line will need to be added to all php.ini files, usually located in /etc/php*.


5. Restart Web server

Now restart the web server and you’re good to go:

# /etc/init.d/httpd restart

6. Test Connect:

The module should now be usable by all PHP interfaces. Call the excellent Gearman API functions for PHP now.

To test using the PHP command line interface, create gearman_version.php with the following contents:

This can then be run on the command line:

$ php gearman_version.php

You can also read the getting started guide from this page. Or if you want to install it through unix package manager you can also follow this post

Hope it’ll help someone!

murshed ahmmad khan (usamurai) on May 1st, 2013
  • Sharebar

What is Gearman

Installing Gearman on CentOS 6.2

The latest Gearman version available in the EPEL repository is not always up to date. The latest version of Gearman at this moment is 1.1.6. So, here is the procedure to install the Latest version from source. It’s easy to install but I’ve run into some problems while installing that in an amazon EC2 large instance. So added the troubleshooting parts too.

Install Gearman’s dependencies

Use yum to install the dependencies that Gearman needs:

yum install uuid-devel libuuid libuuid-devel uuid boost-devel libevent libevent-devel

Download the latest gearmand source

Download the latest Gearman version from Launchpad. I’ve picked Gearman 1.1.6

# cd /usr/share/
# wget

Untar, compile and install

Now unpack it (gearmand version 1.1.6 in this example):

# tar -xvzf gearmand-1.1.6.tar.gz

and then compile and install it:

# cd gearmand-1.1.6

# ./configure && make && make test && make install

That’s all, gearman is installed and ready to use.

Build Troubleshoot:

Unfortunately, for my case it shows couple of errors and then terminated. Here is how I resolved that.

1. While configuring, i’ve got the following error:

checking for the toolset name used by Boost for g++… configure: WARNING: could not figure out which toolset name to use for g++

checking for Boost headers version >= 1.39.0… no
configure: error: cannot find Boost headers version >= 1.39.0

Solution: The reason is either you don’t have the “boost-devel” package installed, but I had already installed it before in the first phase (yum install boost-devel). For my case, it seems that I didn’t install g++ (found in the gcc-c++ package). So Installing the gcc-c++ package fixed the issue. ref: Building Gearman 0.27 on CentOS 6

# yum install gcc-c++

2. Now it proceeds further but throws error while running “make”, while compiling the libhostile.c file:

libhostile/function.c: In function ‘print_function_cache_usage’:
libhostile/function.c:54:3: error: ‘for’ loop initial declarations are only allowed in C99 mode
libhostile/function.c:54:3: note: use option -std=c99 or -std=gnu99 to compile your code
CC libhostile/libhostile_libhostile_la-poll.lo
make[1]: *** [libhostile/libhostile_libhostile_la-function.lo] Error 1
make[1]: *** Waiting for unfinished jobs….
libhostile/poll.c: In function ‘poll’:
libhostile/poll.c:93:9: error: ‘for’ loop initial declarations are only allowed in C99 mode
libhostile/poll.c:93:9: note: use option -std=c99 or -std=gnu99 to compile your code
make[1]: *** [libhostile/libhostile_libhostile_la-poll.lo] Error 1
make[1]: Leaving directory `/usr/share/gearmand-1.1.6′
make: *** [all] Error 2

The solution was hard to find, but as it suggests it is failing because the -std=c99 is required. The libhostile C code requires C99. There are some bug reports for this, but forcing the CFLAGS environment variable will fix this.

Solution: Run ./configure –help, you will see a list of configurable variables.

[.. gearmand-1.1.6]# ./configure –help

Some influential environment variables:
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L if you have libraries in a
nonstandard directory

I tried to specify gnu99 library,
# CFLAGS=-std=gnu99 ./configure && make && make test && make install

or you can also use c99, and it works:

# CFLAGS=-std=c99 ./configure && make && make test && make install

ref: libpq configuration on ubuntu

3. Finally I ran into the mysql.h header file missing error while in “make”:

libgearman-server/plugins/queue/mysql/ fatal error: mysql.h: No such file or directory
compilation terminated.

Solution: The solution is simple, i had missing “mysql-devel” package. So installing it solves the problem.

# yum install mysql-devel

so now you can run the gearman as below:

# gearmand -d -u root

Next to code Gearman’s client and worker process you need to install Gearman PHP extension. It’s very easy and straightforward, to do so, please follow this link: Installing Gearman PHP extension on CentOS

You might also look into this:
1. Installing Gearman on CentOS 6.2
2. Getting started with Gearman
3. Gearman 0.14 on CentOS 5.5 and PHP bindings

Hope that it’ll help someone.

murshed ahmmad khan (usamurai) on November 15th, 2011
  • Sharebar


I had a chance to speak at PhpXperts Seminar 2011. As usual it was a wonderful event and the crowd was rocking! I talked about Apache-Solr and the title was: Apache Solr! Enterprise search solutions at your fingertips! It was on hot shared list in facebook that day!

Here is the slides in slideshare:

Apache Solr! Enterprise Search Solutions at your Fingertips! from Murshed Ahmmad Khan

I wish to share more fine tuning, integrating and troubleshooting on Apache-Solr & Nutch in coming days. Stay tuned!!

Tags: , , , ,

murshed ahmmad khan (usamurai) on November 8th, 2010
  • Sharebar

I was a speaker in the phpxperts seminar 2010 here in Dhaka. The event was fabulous! Big crowd; Big arrangement; Excellent show! Nearly 400+ people participated the seminar with a festive zeal and waited 6-8 hours until it reached to the end! That was awesome. The other topics for the seminar was also very interesting and covered a wide variety of subjects.

Beauty of Web... phpxperts seminar 2010

Beauty of Web... phpxperts seminar 2010

Here is my talk, “Even Better Debugging; equipped yourself with powerful tools”. It was aimed for the PHP developers to make them aware of the debugging techniques from primitive to the advanced. Anyway as the time was limited to only 14 minutes i couldn’t cover much interesting things. Have a wish to create the second part of this slide. Any of your comments, feedback will be appreciated!!

Here is a brief description of the event in the MSDN community news blog. You can also enjoy the video of this seminar from here:


Tags: , , , ,

  • Sharebar

While checking my site statistics in Google Analytics in the “Traffic Sources” >> “All Traffic sources” tab I’ve found some suspicious domain names as the referral of my site… such as

  • / referral
  • / referral
  • / referral
referral spam shown as red mark

referral spam shown as red mark

  • what is a Referrer Spam?
    After a quick check, it became obvious that none of the sites actually don’t have any actual referring links to my site but the things might call Log Spam, Referrer spam or Referrer Bombing. From Google Analytics forum,

    It is a method of attracting direct visits from a webmasters, faking traffic for a paid-for-inclusion-directories or annoy webmasters by posting fake message or fake keywords. Also old public stats programs like Webaliser or AWStats showed a backlink to the faked referrer which had SEO benefits for the spammer. (Note: GA is defaulted to private, so referrers are not publicly posted, as far as I am aware).

    But be known that spam referrals will NOT affect the site’s search engine positions (SERP`s), these 2 issues are COMPLETELY unrelated.

  • How the spammers do it?
    The spammers can collect the GA accountID`s (e.g UA-0000000-1) in a number of ways and then can paste these accountID found above into GA tracking code hosted on their domains e.g. and then can send traffic to these internal pages. It happens as any webpage that has the tracking code of your Analytics account installed on it will be tracked by your Analytics account. This is irrespective of whether it is your domain or not. The only way to stop tracking the page would be to remove the code from it by contacting with the site owner.
  • How to check whether you are affected by this:
    1. Go to “visitors tab” >> “network properties” > “hostnames” and look for or any unknown domains, e.g. If you see sites listed within hostnames are something like
    thebesthosting .org / gps-brasil.blogspot .com / notebooks-brasil.blogspot .com / www.web .com

    The list hostnames shows the unknown domains calling my GA Id

    The list hostnames shows the unknown domains calling my GA Id

    2. Search for allintext:UA-0000000 or “UA-0000000” on google (you can even setup a google alert to be notified if google finds a site your accountID) – To check for if anyone using your exact GA Id –

    3. Do a “Site Search” in the suspected site. e.g. do a site search on to find the page with your accountID.

  • How to Fix this:
    Add an include Hostname filter for to prevent faked visits from thebesthosting .org and others.

    Filter Type:
    Advanced > INCLUDE
    case sensitive: no

    Include filter by hostname

    Include filter by hostname

    IMPORTANT: it is best to have a backup profile with no filters applied. Thus if you accidentally clicked the “exclude” button rather than “include” or mistyped you domain name, then no traffic would be included, so be careful with filters using the hostname field.

    * google cache, MSN translate visits will also be shown in the hostname report. This is because when a user views the cache of your page, the tracking code still runs, but this is hosted on google servers not your hostname.



  • What is a website profile in Google Analytics
  • murshed ahmmad khan (usamurai) on September 29th, 2009
    • Sharebar

    at first, what is actually a snippet and sitelinks in terms of google search result? from seo weekly…

    “The snippet is the 2-line summary that appears along with the link to the website. Sitelinks are additional links to deeper pages or directories within the main site that is listed at number one for the search term.”

    if you search with the term “somewhereinblog” in google, you will see google sorted up some sitelinks for you(see the screen shot below).

    snippet & sitelinks of a normal search result

    snippet & sitelinks of a normal search result

    let’s look at another example…

    sitelinks result for facebook

    sitelinks result for facebook

    viewing the sitelinks in the result, some questions quickly ran through in my mind and finally i got the answers which i would like to share with you all.

    1. question #1: can i set such links for my other sites also?

    • snippets are automatically generated. so you can’t place them by paying money.
    • sites with traffic levels above a certain level are usually listed with snippets.
    • sites with high traffic might not include snippets in the listing if the most relevant page being served is not the homepage.

    so somewhereinblog has good traffic. sitelinks for other sites is subject to the traffic, you can do nothing here other than trying to increase the traffic of your site.

    2. question #2: can i customize the sitelinks ?i want to place some other links say “groups”, “bangla settings”, “kono somosha” etc. under the result rather than showing some other less important links.

    • the google snippets’ sitelinks are usually the most popular links as determined by visitor usage ( it collects site usage data via google analytics, google toolbar etc.).
    • so i can’t add my favorite links here… it is created automatically based on popularity to help the users to go there directly.

    3. question #3: but i don’t like some links anyway… can i remove the links that i dislike ?

    • if you think that the sitelinks displayed for your site are inappropriate or incorrect, you can block them so that they no longer appear(from “webmaster tools”).
    • it’s also notable that google only display sitelinks when a site has a minimum of three sitelinks available. if you have two or fewer unblocked sitelinks, no sitelinks at all will appear in google search results for your site.

    4. question #4: hmm, i know about my site better than you. you should have the feature of adding links also… grrrr…

    so, now things are pretty clear to me. not bad at all. but getting the right answers need me to search several times in several ways. so i thought it would be better to share it with you all. may be you also find it interesting.

    thank you all :).

    references: *** interested people can read these articles too…

    1. google search result snippets
    2. sitelinks help content from google support page
    3. video: anatomy of a search snippet from matt cutts blog

    N.B. it’s a pretty old note. posting lately ;).

    Tags: , , ,

    • Sharebar
    your say for election banner; join somewhereinbangladesh/community

    somewhere in…bangladesh community members has been successfully covered up the national election of bangladesh recently. for the updates to be accessible in more versatile way, people would send the updates from mobile phone by sending sms in front of the polling centers.

    read the global voices online post bangladesh: microblogging an election and french tv news footage and digiactive post about the excellent usage of this microblogging platform to cover up the election.

    have a look at the updates below they have sent through this wonderful micro blogging platform during the election time…

    aawaj microbloggers covering up the election

    aawaj microbloggers covering up the election



    after the election… this micro blogging platform has grown up to focus the local communities of the country. and let the people interact more with their own locality… thus creating colorful moments by togetherness.

    have a look at the real time activities of the community below…

    community updates from somewherein…bangladesh community

    if you would like to add the above widget in your site, it’s very simple to do that. just add the following javascript in your site and you will get the live feeds ready to be shown in your site.

    <script src=”;sortby=activity_id&amp;order=true&amp;limit=5′”></script>

    register yourself here ( to be a part of this growing colorful world. you will not regret this, i promise :).

    Tags: , , , , ,