This guide will explain how to install memcache.
To install the server:
yum search memcached yum install memcached php-pear chkconfig memcached on service memcached start
To install php,pecl,memcache extension:
pecl search memcache
The latest stable version is memcache 2.2.7.
You need to install dependencies before installing memcache:
yum install php-devel gcc zlib zlib-develTo install php extension:
pecl install memcache
Insert the extension in php.ini:
vi /etc/php.iniInsert below line to php.ini:
extension=memcache.so
To create php test script:
vi /var/www/html/memcache.php
<?php $memcache = new Memcache; $memcache->;connect('127.0.0.1', 11211) or die ("Cannot connect"); $version = $memcache->getVersion(); echo "Version: ".$version."
\n"; $tmp_object = new stdClass; $tmp_object->test1 = 'value1'; $tmp_object->test2 = 472; $memcache->set('key', $tmp_object, false, 20) or die ("Cannot save data"); echo "Stored data in the memcache for 20 seconds
\n"; $get_result = $memcache->get('key'); echo "Data from the cache:
\n"; var_dump($get_result); ?>
No comments :
Post a Comment