The Passionate Craftsman

Ruby, PHP, MySql, Software engineering and more.

Wednesday, 8 July 2009

Memcached + PHP + Win 32 + ZendServer CE

If you have the misfortune to develop PHP applications on a Windows box and you want to develop and learn mamcache, this is a quick recipe, but I assume that you have already installed ZendServer CE.

Download a port of memcache to Win32 platform: Then do the following:

1. Unzip the binaries in your desired directory (eg. c:\memcached)
2. Install the service using the command: 'c:\memcached\memcached.exe -d install' from either the command line
3. Start the server from the Microsoft Management Console or by running the following command: 'c:\memcached\memcached.exe -d start'

The the server, by default is listening on port 11211.

When you have started the memcache service you need to activate the PHP module. In ZendServer CE you already have the dll, so go to C:\Program Files\Zend\ZendServer\etc - I presume that you have your ZendServer CE installed in C:\Program Files\Zend\ZendServer\ - uncomment this line:


Restart the server (Apache ZendServer) and you should see that the module is active. Now you can test your installation with the following script:

connect('localhost', 11211) or die ("Could not connect");

$version = $memcache->getVersion();
echo "Server's version: ".$version."

$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;

$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)

$get_result = $memcache->get('key');
echo "Data from the cache:


Visit the PHP page for memcache:

Labels: , , ,


Post a Comment

Subscribe to Post Comments [Atom]

<< Home