??
php5-memcached is slightly faster than php5-memcache
php5-memcached and php5-memcache are two PHP components that operate memcached. They were developed by different people.
php official website lists their respective usage methods:
1. First, First install apache:
sudo apt-get update
sudo apt-get install apache2
2. Then install php5:
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
3. Then install memcached:
sudo apt-get install memcached
4. Then install php5-memcached and php5-memcache:
sudo apt-get install php5-memcache
sudo apt-get install php5-memcached
5. Finally restart apache2:
sudo service apache2 restart
6. Edit test.php as follows:
<span><?php // Initialize values: 10000 keys of 20 bytes with 40 bytes of data $c = 10000; $values = array(); for ($i=0;$i<$c;$i++) $values[sprintf('%020s',$i)]=sha1($i); echo "memcache vs memcached: $c keys\n"; // Memcached $m = new Memcached(); $m->addServer('localhost', 11211); $start = microtime(true); foreach ($values as $k => $v) $m->set($k, $v, 3600); $time = microtime(true)-$start; echo "memcached set: $time\n"; $start = microtime(true); foreach ($values as $k => $v) $m->get($k); $time = microtime(true)-$start; echo "memcached get: $time\n"; // Memcache $m = new Memcache(); $m->addServer('localhost', 11211); $start = microtime(true); foreach ($values as $k => $v) $m->set($k, $v, 0, 3600); $time = microtime(true)-$start; echo "memcache set: $time\n"; $start = microtime(true); foreach ($values as $k => $v) $m->get($k); $time = microtime(true)-$start; echo "memcache get: $time\n"; ?></span>
7. Run http://machinename/test.php or php /var/www/html/test.php
root@machinename # php /var/www/html/test.php
memcache vs memcached : 10000 keys
~
root@machinename
# php /var/www/html/test2.phpmemcache vs memcached: 10000 keys
Reference documents:
1. https://www.digitalocean.com/community/tutorials/ how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu
2. https://www.digitalocean.com/community/tutorials/how-to-install-and-use-memcache -on-ubuntu-14-04
3. https://www.leaseweb.com/labs/2013/03/memcache-vs-memcached-php-benchmark/