How to install Memcached on Win 7 + WAMP Server, the simplest way of all
You can reach source code of memcached from its official web site. Since it is hard to compile memcached from its source code on Windows platforms, we will use a precompiled package (created for Win 7 + PHP 5.3). Download package from here and extract into C:\wamp\bin folder beside other services. Note that, memcached is a service just like MySQL and you have to connect memcached in order to use it.
- First of all, we have to install memcached as a service. So, open command prompt as administrator in folder C:\wamp\bin\memcached and run:
memcached -d install
- Start the memcached service by running:
memcached -d start
- You can verify if memcached is running by executing this command (You have to see full path of memcached.exe):
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
$memcache = new Memcache;
$memcache->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);
?>