Cache

MEMCACHE

Memcache is a system used to manage the caching of your sites, it allows you to speed up the loading of your pages and reduces the usage of memory, although everything is saved temporairy in the RAM.


To use memcached you have to use the unix socket /var/run/memcached/memcached.sock

For example:

 
<?php
$m = new Memcached();
$m->addServer('//var/run/memcached/memcached.sock', 0);

$m->set('int', 99);
$m->set('string', 'a simple string');
$m->set('array', array(11, 12));
/* L''object' va etre détruit dans 5 minutes */
$m->set('object', new stdclass, time() + 300);

var_dump($m->get('int'));
var_dump($m->get('string'));
var_dump($m->get('array'));
var_dump($m->get('object'));

REDIS

Redis is a more recent cache manager as memcache and allows you to manage the cache more finely with a specific configuration and make it persistent by enabling disk writes

To use it, you have to use the unix socket: /var/run/redis/redis.sock

ex:

<?php
echo "Redis ping<br/>";
$redis = new Redis();
$redis->connect('/var/run/redis/redis.sock');
echo $redis->ping();
?>