Full PHP Environment: Configure memcache in Mac Super Detailed introduction (differentiate the concepts in the Memcache system)

Source: Internet
Author: User
Tags zts
Perfect PHP Environment: Configure memcache in Mac Super Detailed introduction (distinguish the concepts in the Memcache system)

I want to configure the Memcacahe system? Do I have to install libmemcached first?
Oh! No, you need to install libevent! first.
Isn't it called libmemcached?
PHP extension memcached need to install libmemcached! first
Ah! is the extension of Php not called Memcache? How could it be memcached?
Memcache is the entire memcache system!
Yes! Then they say memcached is the daemon of the service side, right.
Yes, memcached is the daemon of the memcache system.



I've been confused by these concepts before, so let's get it over with today. Rookie experience, master do not spray.

Concept

First of all: Memcache is a project of Danga, the first LiveJournal service, originally developed in order to speed up LiveJournal access, was later adopted by many large-scale websites. Memcache on behalf of the entire project, it includes the service side (memcached) and the client (memcache). (In fact, give the project a name, this name is just called memcache)

First, the service side--memcached

Mecache the entire project service side is memcached, saw, more a "D" letter, have not encountered "mysqld", "httpd" and so on, are the same, they are also the Guardian process, usually persistent connection, long-term waiting life. Say the popular point, the service is actually a powerful basket, you can put things in, like DB, you can save data in db, then DB is also a service side, we now change to save data into memcached.

Ok! Let's start with the service side, first install mecached this server:

There are two ways of installing

(1) Installation method: Installation using the Super Homebrew management software tool

1

$brewinstall memcached

With the Homebrew tool installation, one advantage is not so troublesome, to find the source package, two advantage is that many dependent software will search the installation itself.

Ok! During the installation, you will see that it installs a Libevent library First! The basic condition for memcached is this libevent, so you must install it first! (Well, here's the idea of Libevent and memcached.) )

(2) Installation Method II: Use the source package installation:

1. Go to the official website http://libevent.org/? Download the latest source code, for example you can use the libevent-2.0.20-stable.tar.gz (when I use the 2.0.21. See no, so you use the tool, it will automatically help you install libevent rely on the library, your own installation will go to find source package. )

2. Extract to/usr/src directory, execute command: sudo tar-zxvf libevent-2.0.20-stable.tar.gz-c/usr/src

3. Enter the directory after decompression and execute the command in sudo mode:

1

2

3

sudo ./configure --prefix=/usr/local/libevent ;

?

?make && make install

Ok! Let's test the service side now.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

Engine:libevent app$ telnet localhost 11211

?Trying ::1...

?telnet: connect to address ::1: Connection refused

?Trying 127.0.0.1...

?Connected to localhost.

?Escape character is '^]'.

?stats

?STAT pid 50

?STAT uptime 23245

?STAT time 1396500024

?STAT version 1.4.5

?STAT pointer_size 64

?STAT rusage_user 0.270129

?STAT rusage_system 0.818887

?STAT curr_connections 5

?STAT total_connections 9

?STAT connection_structures 6

Well, everything's fine!

Second, the client--memcache

Mecache the entire project client is also called Memcache (name is just a codename, you can call Memcache, he can also call Memcache, we can call Memcache), with the service side basket, that must have a client put things into the basket, What's the use of a basket? Server installed, the client in what language can be engaged in, I here with PHP to do the client. (You can also use Java,c,python,ruby ....) )

Please seriously note: The expansion of PHP is divided into memcache and memcached (Eh, name is just a code), that is to say that both extensions can be used, and memcached is based on libmemcached (that is, a dependent library). I heard that the former one is native, and the latter one is more powerful than the previous one. It is recommended to use memcached extensions based on the libmemcahced library. Supports CAS operations provided by Memcache, and is also more stable and efficient.

I install memcached here.

(1), using the super-strong homebrew management software tool installation:

1

$ sudo brew install php53-memcached

Installation log:

1

2

3

4

5

6

7

8

9

10

11

==> Installing php53-memcached dependency: libmemcached

?

==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/libmemcache

?

######################################################################## 100.0%

?

To finish installing memcached forPHP 5.3:

?

* /usr/local/etc/php/5.3/conf.d/ext-memcached.ini was created,

?

donot forget to remove it upon extension removal.

Ext-memcached.ini? The location of custom PHP extensions is recorded in the file.

1

vi ext-memcached.ini

We see:

[Memcached]

extension= "/usr/local/cellar/php53-memcached/2.1.0/memcached.so"

OK, let's go to this path now to find the memcached.so extension, put it CP into your own extension directory

The default extension path for PHP in Mac is:

1

cd /usr/lib/php/extensions/no-debug-non-zts-20090626 (我的php版本是5.3的)

Okay, copy this:

1

cp -p -v? memcached.so? /usr/lib/php/extensions/no-debug-non-zts-20090626

OK, open php.ini, add memcached.so extension path.

extension= memcached.so

Restart Apache (or your own Web services software):

1

sudo apachectl restart

Check with Phpinfo:

?

I

All right, it's done! By the way the Memcache expansion also loaded.

(2), using the source package installation
Libmemcached:?https://launchpad.net/libmemcached? (or http://libmemcached.org/libMemcached.html?) Download the source code,
Memcached: There are two versions one is memcache (Http://pecl.php.net/package/memcache) and the other is a memcached version based on libmemcached (/HTTP/ Pecl.php.net/package/memcached?);

The installation process is not demonstrated. (Will not be the source package with tools, I prefer to use the source package, speed, leverage.) )

Conclusion

In fact, after the concept and the principle of clear, do it more handy.
Clear your mind and travel light.

  • 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.