Monday, 26 November 2012

How to install memcached on xampp - win 7

First download Win32 binary version of memcached here. Extract in any of ur folder outside xampp. I installed in c:/memcached/memcached.exe.

Then Go to your php.ini file usually located in C:/xampp/php/php.ini and find this line:

;extension=php_memcache.dll

then uncomment this line like this:

extension=php_memcache.dll

If you can't find this line add it at the end of the php.ini file:
Then add the following lines beneath this line:
[Memcache]  
memcache.allow_failover = 1  
memcache.max_failover_attempts=20  
memcache.chunk_size =8192  
memcache.default_port = 11211
 
Then download the memcached extension from here. For me php_memcache-5.4-vc9-x86 it works.
 Because I installed latest version of xampp. If the version id not right then it won't work. I've been searched for the correct version for whole day and finally found mine. 
 
Then extract that package in side c:/xampp/php/ext . Now restart ur Apache & MySql.
 
Then goto ur memcahed folder using command prompt and type like this:
c:\memcached\memcached.exe -d install  
If it say already installed or didn't show any errors then its been installed. Then start memcached using this command:
c:\memcached\memcached.exe -d start
 
Now create any test php file and test with memcache class like code given below:
 
<?php  
$memcache = new Memcache;  
$memcache->connect('localhost', 11211) or die ("Could not connect");  
  
$version = $memcache->getVersion();  
echo "Server's version: ".$version."<br/>\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) 
<br/>\n"; 
 
$get_result = $memcache->get('key');  
echo "Data from the cache:<br/>\n";  
  
var_dump($get_result);  
?> 

Thats It!

 
 

2 comments:

  1. In example you using Memcache (without 'd') - not Memcached

    ReplyDelete
  2. in which path the php testing code should be added?

    ReplyDelete