Differences between memcache and memcached and Installation

Source: Internet
Author: User
Article Title: differences between memcache and memcached and its installation. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

What is Memcache?

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.

Memcached is simple and powerful. Its Simple Design Promotes Rapid Deployment and is easy to develop. It solves many large data caches. Its APIs are available in the most popular languages.

Memcache's well-known users include LiveJournal, Wikipedia, Flickr, Bebo, Twitter, Typepad, Yellowbot, and Youtube.

Memcache Official Website: http://memcached.org/

What is Memcached?

Memcache is the project name of the system, and Memcached is the main program file of the system. It runs on one or more servers in the form of a daemon and accepts connection operations from the client at any time, use shared memory to access data.

What is Memcache in PHP?

Memcache in php is a client component used to connect to Memecached.

How to install Memcache?

Install Memcached on the server: (download the source code package from the official website)

System commands

Tar xvf memcached-1.2.6.tar.gz

Cd memcached-1.2.6

./Configure -- prefix =/usr/local/memcached

Make

Make install

Then you can start the memcached daemon:

System commands

/Usr/local/memcached/bin/memcached-p 11211-l 127.0.0.1-d-u nobody-P/var/run/memcached. pid-m 64 M-c 1024

Several parameters:

-P memcached listening TCP port

-L the IP address of the listener. 127.0.0.1 is the local host. You can also write your server IP address, for example, 61.150.91.26. This is the IP address of my server, if you need multiple servers to read the cached data of this memcached instance, you must set this ip address.

-D run in daemon mode and put the program into the background

-U memcached running user, I set nobody

-P memcached pid file path

-Maximum memory available for m memcached

-C memcached maximum number of connections that can be accepted at the same time

If you want to access memcached through socket, you must remove the-l and-p parameters at startup and add the-s parameter:

-S memcached socket file path

Install the memcache extension component in php:

System commands

Tar xvf memcache-3.0.3.tgz

Cd memcache-3.0.3

/Usr/local/php5/bin/phpize

./Configure -- with-php-config =/usr/local/php5/bin/php-config -- enable-memcache

Make

Make install

Memcache compiled according to my environment. so stored in the/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/directory, if your environment is different, you have to modify your php as needed. ini.

The next step is to let php load this extension, edit your php. ini, and add the following lines in the appropriate location (usually the last, or an independent ini file:

Extension = memcache. so

Then restart your phpfastcgi process or apache and run a phpinfo () command to check whether memcache is normal.

Simple use example of php-memcache:

PHP code

  

$ Memcache = new Memcache;

$ Memcache-> connect ('127. 0.0.1 ', '123 ');

$ Memcache-> setCompressThreshold (20000, 0.2); // SET COMPRESSION

Echo $ memcache-> getVersion (); // output the memcached version.

$ Test = array (, 5, 'abcde'); // generates an array

If ($ memcache-> get ('test ')){

Print_r ($ memcache-> get ('test'); // get data

Echo "\ n ";

Echo 'cached ';

Echo "\ n ";

} Else {

$ Memcache-> set ('test', $ test,); // write data

Echo 'no cache ';

Echo "\ n ";

}

?>

Related Article

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.