What is Memcache?
Memcached is a cache system that works by temporarily storing information about the data you use often in RAM. Because the read and write speed of memory is always higher than that of file storage, the use of memcached significantly speed up your system.
Memcached's operating model:
1. Install Memcached
Install the Memcached package
yum install memcached
You should note that there are two memcache packages that exist, memcache and memcached (with the d at the end) as well as two versions of the PHP Extension Module, respectively, php-pecl-memcache and php-pecl-memcached. We will use the 2nd version (with the letter d) because it is stable and supports more functions.
2. Configure Memcached
The most important parameter you need to note is the CACHESIZE, the unit of measurement is MB. For example, below I use 128MB to cache (default 64MB). OPTIONS security configuration only allows local connect to port 11211 only.
vi /etc/sysconfig/memcached
PORT="11211"
USER="memcached"
MAXCONN="10240"
CACHESIZE="128"
OPTIONS="-l 127.0.0.1"
Start Memcached
chkconfig memcached on
service memcached start
Step 1: Check if the memcached service is available on the server
service memcached status
Step 2: Check if php-memcached is integrated
php -m | grep memcache
* : If nothing, install php-memcache
Step 3: Install php-memcache
Install support packages for the installation
yum install php-devel php-pear -y
Install php-memcache
yum install libmemcached-devel
pecl install memcache
Bước 4 : enable memcache
– Check the path of the php.ini file with the command:
php -i | grep php.ini
include the memcache module in php.
You see the line Loaded Configuration File => /usr/local/php56/lib/php.ini
Then type the following command:
echo "extension=memcache.so" >> /usr/local/php56/lib/php.ini
Step 4: Check if the php-memcache module is working or not?
php -m | grep memcache
If it looks like this, you have successfully installed the memcache module.
Good luck !
Minh BKNS
Post a Comment
Post a Comment