As you know, Memcached is great cache system for your web application. Use correctly Memcached will speed up your application so much. So now is how to install memcached, PHP Memcache and PHP Memcached
In Ubuntu 14.04, the installation is very simple, just need one command:
1 |
sudo apt-get install memcached php5-memcache php5-memcached |
Please remember restart apache2:
1 |
sudo /etc/init.d/apache2 restart |
Finally, test your works by writing some PHP scripts.
1 |
vi test.php |
Add php script to test.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php $memcache = new Memcache(); $memcache->connect('localhost', 11211); $memcache->set('test', false); // $flags = false; var_dump($memcache->get('test', $flags)); // bool(false) var_dump($flags); // int(256) - changed to int $memcache->delete('test'); $flags = false; var_dump($memcache->get('test', $flags)); // bool(false) var_dump($flags); // bool(false) - untouched ?> |
Successful result:
1 2 3 4 5 |
thanhson1085@sonnst:~$ php test.php bool(false) int(256) bool(false) bool(false) |