For one of my Zend Framework web applications I’m going to install memcached. I am currently using file cache however think memcached is a much better way to go. This post is one in a series:
1a. Go to your php.ini file usually located in C:/xampp/php/php.ini find this line:
and replace it with:
1b. If you cannot find this line simply add the following line to below where all the ;extension= lines.
2. Add the following to just below the new line
1 [Memcache] 2 memcache.allow_failover = 1 3 memcache.max_failover_attempts=20 4 memcache.chunk_size =8192 5 memcache.default_port = 11211
3. Download the necessary php_memecache.dll file from the following location.
For windows 7 I used the following file:
4. Unzip the php_memcache.dll file and put it into your php ext folder. Usually C:/xampp/php/ext/
5. Download memcached for windows here (make sure it’s thewin32 binary):
6. Unzip and put the memcache.exe file into a desired directory (e.g. c:/memcached/)
7. Open command line in Windows Administrator Mode.
Click start, type in ‘Search programs and Files’ box, wait for the program cmd.exe to appear, right hand click on the icon and select run as administrator
8. Install the memcache service Type the following into the command line
1 c:\memcached\memcached.exe -d install
If you dont get any errors it means it’s worked.
9. Start memcached Type the following into the command line
1 c:\memcached\memcached.exe -d start, or net start “memcached Server”
10. Restart Xampp Apache
11. Test Memcache Create a php file and paste the following code. Then go to the page. If you do not see any errors then it has worked.
1 <?php 2 $memcache = new Memcache; 3 $memcache->connect('localhost', 11211) or die ("Could not connect"); 4 5 $version = $memcache->getVersion(); 6 echo "Server's version: ".$version."<br/>\n"; 7 8 $tmp_object = new stdClass; 9 $tmp_object->str_attr = 'test'; 10 $tmp_object->int_attr = 123; 11 12 $memcache->set('key', $tmp_object, false, 10) or 13 die ("Failed to save data at the server"); 14 echo "Store data in the cache (data will expire in 10 seconds) 15 <br/>\n"; 16 17 $get_result = $memcache->get('key'); 18 echo "Data from the cache:<br/>\n"; 19 20 var_dump($get_result); 21 ?>