Memcache and memcached Introduction and installation Configuration

Source: Internet
Author: User

Memcache Study Summary 1-memcache and memcached introduction and installation Configuration

Perhaps everyone saw Memcache and memcached will be a little dizzy, what is the difference between the two, the following first let's say memcached,memcached is a high-performance distributed memory object caching system for dynamic Web applications to reduce database load. It improves the speed of dynamic, database-driven Web sites by caching data and objects in memory to reduce the number of times a database is read.

Presumably everyone has heard of memcached, is a cache system, we can put some of the data often to query into the cache, to avoid each time to use to query the database. This can greatly speed up the data read speed, but also reduce the pressure on the server, so the general large-volume site will use the memcached.

The difference between memcached and memcache as for the difference between memcached and memcache, in fact, is very simple, one is the server, one is the client, just like MySQL, we enter various SQL statements in the command line can query to the desired results, this is the client, The client receives the command we entered from the server, mysqld is the service side, that is, in response to the client's frontal background process, where the same memcached is the server, and Memcache is the client.

So we have to use memcached, first install the memcached on the server, and run memcached, and then install memcache can be used.

Here we will explain in detail the installation of the memcached server under Linux, and explain the installation of memcache via PHP extensions so that we can test the memcached directly from PHP.

memcached installation (Linux environment) because Memcache used the libevent this library for socket processing, so we also need to install libevent, we first download the two software
#1. Download memcached and libevent, and put them in the/tmp directory: # cd/tmp# wget http://www.danga.com/memcached/dist/memcached-1.2.0.tar.gz # Wget http://www.monkey.org/~provos/libevent-1.2.tar.gz #2. First install libevent:# tar zxvf libevent-1.2.tar.gz# cd libevent-1.2 #./configure--prefix=/usr# make# make install#3. Test libevent for installation success: # Ls-al/usr/lib | grep libeventlrwxrwxrwx 1 root root 21 11?? 17:38 Libevent-1.2.so.1-libevent-1.2.so.1.0.3-rwxr-xr-x 1 root root 263546 11?? 17:38 libevent-1.2.so.1.0.3-rw-r--r--1 root root 454156 11?? 17:38 libevent.a-rwxr-xr-x 1 root root 811 11?? 17:38 libevent.lalrwxrwxrwx 1 root root 21 11?? 17:38 libevent.so-libevent-1.2.so.1.0.3 is also good, all installed. #4. Install memcached, and you need to install the installation location of the specified libevent: # cd/tmp# tar zxvf memcached-1.2.0.tar.gz# cd memcached-1.2.0#./configure-- with-libevent=/usr# make# Make install if there is an error in the middle, please carefully check the errors and configure or add the appropriate libraries or paths according to the error message. When the installation is complete, the memcached will be put into the/usr/local/bin/memcached, #5. Test for successful installation memcached:# Ls-al/usr/local/bin/mem*-rwxr-xr-x 1 root root 137986 11?? 17:39/usr/local/bin/memcached-rwxr-xr-x 1 root root 140179 11?? 17:39/usr/local/bin/memcached-debug


All right, the memcached was installed successfully.

Below installs memcache PHP extension 1. Select the Memcache version that you want to download in Http://pecl.php.net/package/memcache.
2. Installing the PHP memcache extension
Tar vxzf memcache-2.2.1.tgzcd memcache-2.2.1/usr/local/php/bin/phpize./configure--enable-memcache-- With-php-config=/usr/local/php/bin/php-config--with-zlib-dirmakemake Install


3. There will be a hint like this after the installation is complete:
Installing Shared extensions:/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/

4. Change the Extension_dir in php.ini = "./" To
Extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/"

5. Add a row to load the memcache extension: extension=memcache.so

6, modified not configured after restarting PHP

Here we have installed the Memcache server and the client, let's do a simple test through PHP

Memcache Functional Testing First we have to start the installed memcached on the server.
/usr/local/bin/memcached-d-M 10-u root-l 127.0.0.1-p 11211-c 256-p/tmp/memcached.pid

Parameter description:
The-D option is to start a daemon,
-M is the amount of memory allocated to Memcache, in megabytes, I'm 10MB,
-U is the user running memcache, I am root here,
-L is the server IP address of the listener, if there are multiple addresses, I specify the server IP address 192.168.0.200,
-P is the port that sets Memcache listening, I set here 12000, preferably more than 1024 ports,
The-c option is the maximum number of concurrent connections to run, the default is 1024, I set the 256 here, according to the load of your server to set,
-P is set to save memcache PID file, I am here to save in/tmp/memcached.pid,

then write the PHP test:

[PHP]View Plaincopy
    1. < PHP
    2. $mem = new Memcache;
    3. $mem->connect ("127.0.0.1", 11211); //IP and port number here is the previous step we started memcached specified, otherwise it will not connect
    4. $mem->set (' key ', ' set a value ', 0, 60);
    5. $val = $mem->get (' key ');
    6. echo $val;
    7. ?>


Reference Source:
Memcache Study Summary 1-memcache and memcached introduction and installation Configuration
Http://www.lai18.com/content/407157.html

Memcache and memcached Introduction and installation Configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.