Setting up the memcached in windows is easy, download the Win32 binary and put it somewhere. Fire the following commands:
memcached.exe -d install
/* Install the memcached as windows service */
/* Install the memcached as windows service */
memcached.exe -d start -m 512
/* Start the memcached instance with maximum memory 512M */
/* Start the memcached instance with maximum memory 512M */
Configuring PHP using the Memcached:
- Download php_memcache.dll in Google as pecl4win.php.net was down in 2008.
- Copy the php_memcache.dll to \ext
- Edit the php.ini to include the line
Restart Apache
extension=php_memcache.dll
<?php
$memcache = new Memcache;
$memcache->addServer("localhost",11211); /* Default Port */
$memcache->addServer("localhost", 22333); /* Comment this out if you are not starting multiple incidence */
print "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"));
?>
$memcache = new Memcache;
$memcache->addServer("localhost",11211); /* Default Port */
$memcache->addServer("localhost", 22333); /* Comment this out if you are not starting multiple incidence */
print "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"));
?>
Read the PHP Memcache Menu
There is another key-value pair cache called Redis. Will talk more in other posts.
No comments:
Post a Comment