Memcache Installation in PHP (Wamp Server)
what is Memcache?
Memcache is a caching system used to speed up web applications by holding small pieces of arbitrary data, it could be broadly compared to the $_SESSION variable in PHP, but memcache works across the whole application not just on a per user basis and has been successfully proven to make great gains in speed increases on web applications.Memcache was designed with Linux in mind and not windows, so it has posed some installation issues because Windows users are not so familiar with having to compile code from source as memcache does not come with any installation software.
Installation:
- Download this package, here- Unzip Memcached application in C:/memcached folder
- Open command prompt, Type below command to install
C:\memcached>memcached.exe -d install
- Now its time to start the Memcache server
C:\memcached>memcached.exe -d start
(or)
C:\memcached>net start memcached
The memcached service was started successfully.
Hope you have installed Memcache in your system successfully. Now its time to configure with Wamp server.
Installing PHP Extension:
- Download DLL file from this link- Add extension in php.ini file
extension=php_memcache.dll
- Restart your WAMP server.
Test PHP sample file for Memcache:
<?php$memcache = new Memcache;
$memcache->connect("localhost",11211); # You might need to set "localhost" to "127.0.0.1"
echo "Server's version: " . $memcache->getVersion() . "<br />\n";
$tmp_object = new stdClass;
$tmp_object->str_attr = "test";
$tmp_object->int_attr = 123;
$memcache->set("key",$tmp_object,false,10);
echo "Store data in the cache (data will expire in 10 seconds)<br />\n";
echo "Data from the cache:<br />\n";
var_dump($memcache->get("key"));
?>
Output:
Server's version: 1.4.4-14-g9c660c0Store data in the cache (data will expire in 10 seconds)
Data from the cache:
object(stdClass)[3]
public 'str_attr' => string 'test' (length=4)
public 'int_attr' => int 123
Hope you enjoyed the tutorial. For any doubts/clarification please drop it into comments section.
Comments
Post a Comment