Wednesday, November 26, 2014

Installing Memcached with WAMP

How to install memcache on wamp server

Follow below instructions
1> The first thing in installing memcached with wamp is to install the Memcached service. download here the Win 32 binary version.
2> Inside the download you will find a memcached.exe file. Extract this to C:\memcached
3> Now to install the service, open a command window and enter the following

- Install the memcached service by running:
C:\memcached\memcached.exe -d install

- Start the memcached service by running:
C:\memcached\memcached.exe -d start

- You can verify if memcached is running by executing this command (You have to see full path of memcached.exe):
C:\memcached\wmic process get description, executablepath | findstr memcached.exe

Install PHP Memcache extension (php_memcache.dll)
- If you don’t have php_memcache.dll in folder C:\wamp\bin\php\php5.x\ext, download it from here and extract into this directory.
- Open php configuration file php.ini from C:\wamp\bin\apache\Apache2.x\bin directory, and add the following line to the end of Dynamic Extensions block which lies between lines 920 and 990 roughly.

extension=php_memcache.dll

- Restart all services of Wamp Server through the system tray menu.

Testing Memcached with PHP

</?php
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect to memcache");
$version = $memcache->getVersion();
echo "version: ".$version."
";
$tempObject = new stdClass;
$tempObject->strAttr = 'Testing';
$tempObject->intAttr = 0123456789;
$memcache->set('keys', $tempObject, 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('keys');
echo "Data from the cache:
";
var_dump($get_result);
?>