Memcached : Use on PHP2024/07/22 |
This is the example to use Memcached on PHP. |
|
[1] | Install PHP Memcached Client Module. |
root@dlp:~# apt -y install php-memcached
|
[2] | This is the Basic usage on PHP. |
ubuntu@dlp:~$
vi use_memcache.php <?php $memcache = new Memcached(); $memcache->addServer('localhost', 11211); $memcache->setOption(Memcached::OPT_COMPRESSION, false); // set and get a Key $memcache->set('key01', 'value01'); print 'key01.value : ' . $memcache->get('key01') . "\n"; // append and get a Key $memcache->append('key01', ',value02'); print 'key01.value : ' . $memcache->get('key01') . "\n"; $memcache->set('key02', 1); print 'key02.value : ' . $memcache->get('key02') . "\n"; // increment $memcache->increment('key02', 100); print 'key02.value : ' . $memcache->get('key02') . "\n"; // decrement $memcache->decrement('key02', 51); print 'key02.value : ' . $memcache->get('key02') . "\n"; ?> # run ubuntu@dlp:~$ php use_memcache.php key01.value : value01 key01.value : value01,value02 key02.value : 1 key02.value : 101 key02.value : 50 |
Sponsored Link |
|