Tools‎ > ‎

Memcached

Memcached needs direct support in your PHP apps to have any effect.

XCache speeds up all PHP scripts (avoids the parse-and-compile step after the first time)

Official site


Setup on Debian

# Install memcached
apt-get install memcached php5-memcache

# Confirm memcached is running
netstat -tap | grep memcached

# Restart Apache
/etc/init.d/apache2 restart


Test Memcached


test-memcached.php

<?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);

?>


Expected output

Server's version: 1.2.2
Store data in the cache (data will expire in 10 seconds)
Data from the cache:
object(stdClass)#3 (2) { ["str_attr"]=> string(4) "test" ["int_attr"]=> int(123) }

Wikipedia



Comments