Oliver Nassar

I can be reached at onassar@gmail.com.

For my open source work, check out github.com/onassar


Installing a specific PECL-extension version

View more posts

My EC2 micro instance has been experiencing major spikes of traffic over the past month. By major, I mean my outbound traffic went from ~0.75 gigs per month to almost 150. While that is a topic for another post, it's directly related to my obvious-discovery of how to, and why to, specify your PECL-extension version when installing it.

The Problem

I have a build script, which includes the setting up of memcached (with libmemcached as prerequisite). This worked for a long time, until today, when it didn't.

The installation is covered in my AWS EC2 Micro Instance Setup article, about 1/3 of the way down. The code block responsible looks as follows:

sudo updatedb
cd
sudo apt-get -y install g++
wget http://launchpad.net/libmemcached/1.0/0.39/+download/libmemcached-0.39.tar.gz
tar zxvf libmemcached-0.39.tar.gz
cd libmemcached-0.39/
./configure
make
sudo make install
cd /usr/lib
sudo ln -s /usr/local/lib/libmemcached.so
sudo pecl install memcached
sudo rm -r ~/libmemcached-0.39
sudo rm ~/libmemcached-0.39.tar.gz

The error I was getting (mind you, I've run this exact code against my Ubuntu 11.10 box on AWS many times before), included:

make *** php_memcached.lo error 1 no such file

And:

make[1]: *** [libhashkit/libhashkit_libhashkit_la-aes.lo] Error 1

I googled a bit, which brought me to the post How to install PHP memcached on an Ubuntu server. It included the comment:

nvm, figured it out. i didn’t notice that libmemcached didn’t install correctly. did that and pecl install worked.

This got me looking at my libmemcached.

I didn't discover an issue there (since 0.39 was still valid).
Rather, the PECL-extension had been upgraded: http://pecl.php.net/package/memcached

When I was issuing the command sudo pecl install memcached, it was compiling in version 2.1.0, which is the latest stable one. The issue? This version doesn't play nicely (or at all) with libmemcached v0.39

It took me quite a while to figure this out.

The Solution

Changing sudo pecl install memcached to sudo pecl install memcached-1.0.2. Yup, that's it. The php.net post PHP: Compiling shared PECL extensions with the pecl command outlines the passing in of a version string.

At the time of writing my build script, the stable build that PECL downloaded and installed was 1.0.2 which worked with libmemcached v0.39. When that got upgraded, it prevented the memcached library from working.

Why not install a newer version of libmemcached?

I tried. It failed (dependency related). And while that's probably the right approach long-term (since the recent version of libmemcached is up to 1.0.11 and probably contains a lot of features and bug fixes), for now, this gets me to the point of usability.

The Reminder

When I'm installing extensions from applications, which are detecting versions automatically, be explicit. This goes for my installing APC and PECL_HTTP. This ought to prevent conflicts when they update their systems.

While this will prevent you from getting the most recent/up-to-date version, it'll ensure that it works the way you designed and tested it to.

More Reading

In my post Memcached/libmemcached for PHP, I outlined why I chose the memcached and libmemcached versions that I did. That helped the light-bulb turn on :)