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: http://jehiah.cz/projects/memcached-win32/. 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:

extension=php_memcache.dll

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."
\n";

$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)
\n";

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

var_dump($get_result);
?>

Visit the PHP page for memcache: http://php.net/memcache

Labels: , , ,

Friday, 5 June 2009

Performance of PHP platforms

I tested some different platforms to see which one has the best perfomance. I tested Zend Server CE, a SAMP environment and Resin with Quercus.

The Zend Server is running on my PC:

OS: Windows XP
Processor: P4 HT
RAM: 1GB

This is the script that I used to test the performance:

missing

This script is executed in 4.317 seconds on the Send Server CE.

The Resin Server Pro, with the compile option for better performance, executes the script in 12.72 seconds. The Resin Server with GPL license, without the compile option on, executes the script in 13.60 seconds. Both of versions of Resin are installed in my PC.

The SAMP server, is on a Solaris server, 32GB RAM and many CPUs. The execution time on Soalris is 36.79 seconds! On Solaris is used the Apache Handler and there is only eAccelerator, not APC.

My conclusion is that having a caching module on, it makes a big difference. Having Zend Server CE makes a huge difference. I do not think that Resin Pro is quite better than the GPL version, since the difference is very little.

In the end I would choose Resin Server with GPL license. A unique benefit is to have the integration of PHP with Java and the other dynamic languages, running on the JVM.

Labels: , , , ,