What is memcache?
Source code: http://code.google.com/p/memcached/downloads/list
Memcache is a free and open source code, high-performance, and allocated memory object cache system. It is used to accelerate dynamic web applications and reduce database load.
It can cope with any number of connections and use non-blocking network I/O. Because its working mechanism is to open up a space in the memory, and then create a hashtable, memcached self-manages these hashtable.
What is memcached?
Memcached is the main program file of the memcache system. It runs on one or more servers in the form of a daemon. It accepts connection operations from the client at any time and uses shared memory to access data.
What is memcache in PHP? Memcache mentioned in PHP is one of the extensions supported by PHP for connecting to memecached (which can be viewed by phpinfo), such as mbstring and eaccelerator.
Simply put
Memcache is the name of the total cache system project, which is easy to be confused with memcache in PHP.
We often mention that memcache is actually a memcache in PHP, that is, PHP's memcached extension support.
We often mention that memcached is the server-side main program file and the server-side installer.
To make your program fly, you must install the memcached server program and the memcached extension of PHP. If you want to use memcache for the cache system, both memcache and memcached must be installed.
Install memcache
# Cd/usr/local/src # Wget http://pecl.php.net/get/memcache-2.2.5.tgz # Gzip-D memcache-2.2.5.tgz # Tar xvf memcache-2.2.5.tar # Cd memcache-2.2.5 |
The following sentence uses the directory/usr/local/PHP where PHP is located as an example. If your PHP has changed, replace the/usr/local/PHP section in the following sentence.
#/Usr/local/PHP/bin/phpize #./Configure -- enable-memcache -- With-PHP-Config =/usr/local/PHP/bin/PHP-config -- With-zlib-Dir # Make & make install |
Add memcache to PhP Extension
# Vi/etc/PHP. INI (/etc/PHP. the INI address is my PHP. INI location, if you do not know your php. where is the ini? # Find/-name PHP. INI, or pass a probe phpinfo to find the configuration file (PHP. INI) path) in PHP. INI location.
Add at the end
Press I on the disk to start editing.
CTRL + F pull the page to the bottom and add it before [Zend]
Extension_dir = "/usr/local/PHP/lib/PHP/extensions/no-debug-non-zts-20060613 /" Extension = memcache. So |
Press ESC and then enter
: WQ
Save and exit
Restart your web server, such as Apache
/Etc/init. d/httpd restart |
Next, refresh the PHP probe and check if there is any such probe. If yes, it is installed.
Memcache
Version 2.2.5memcache
Version 2.2.5
Install memcached
To install memcached, install libevent first.
If centos is used, yum can be installed.
# Yum install libevent-devel |
If the yum system is not supported, you can install libevent like this.
# Cd/usr/local/src # Wget http://www.monkey.org /~ Provos/libevent-1.4.12-stable.tar.gz # Tar vxf libevent-1.4.12-stable.tar.gz # Cd libevent-1.4.12 #./Configure -- prefix =/usr/local/libevent # Make & make install |
Install memcached
# Cd/usr/local/src # Wget http://cloud.github.com/downloads/saberma/saberma.github.com/memcached-1.4.4.tar.gz # Tar vxf memcached-1.4.4.tar.gz # Cd memcached-1.4.4 #./Configure -- prefix =/usr/local/memcached # Make & make install |
After the installation, start memcached and allocate 32 MB of memory (32 indicates the number of memory used, which can be modified as needed)
/Usr/local/memcached/bin/memcached-D-M 32-l 127.0.0.1-P 11211-u Root |
Add memcached to the startup Item
Press I on the disk to start editing.
Add at last
/Usr/local/memcached/bin/memcached-D-M 32-l 127.0.0.1-P 11211-u Root |
Press ESC and then enter
: WQ
Save and exit
If needed, you can reboot it, but it should have taken effect without reboot ~
Acceleration Effect Test
Use discuz X1 with no load for a test. If it is not started
GMT + 8, Processed in 0.038893 second (s), 2 queries. |
The effect after the cache is enabled, but the VPs is not as effective as adding eaccelerato to the cache.
GMT + 8, Processed in 0.008383 second (s), 2 queries, memcache on. |
It's done. You can close the job !~~