Speaking of the relationship between PHP's Memcache & Memcached extensions, do you understand it?

Speaking of the relationship between PHP's Memcache & Memcached extensions, do you understand it?

[51CTO.com original article] Memcached is a free, open source, high-performance, distributed memory cache system. Many WEB programmers should be very familiar with it. Many WEB programmers often use it to cache data in the database to improve the performance of websites or applications. As a popular language for website development, PHP certainly supports Memcached. However, when we open the official PHP manual, we find an interesting situation, that is, PHP has two extensions that provide similar functions, namely Memcache and Memcached extensions. What is the relationship between these two extensions? And are the two extensions the same? With these questions, let's analyze them one by one.

Some basic concepts

In fact, Memcached is a C/S application, so there are two basic concepts:

  • Memcached server. It is the application end that actually provides data caching. This end is an independent process and opens corresponding ports for Memcached clients to perform operations such as adding, deleting, modifying, and querying data.
  • Memcached client. As long as it can communicate with the Memcached server and complete the corresponding data operation functions, we can call it a Memcached client. For example, the two PHP extensions mentioned in this article can both be called clients.

Related knowledge and operating principles of the two extensions

In the pecl official extension library, we can see that the birthday of the Memcache extension is February 26, 2004, and the birthday of the Memcached extension is January 29, 2009. Haha, looking at these two birthdays, what do you think of?

From the birthdays above, we can see that Memcache was born first, and Memcached was born later. Let's take a look at the definitions of the two:

  • Memcache extension. This extension provides both procedural and object-oriented approaches.
  • Memcached. This extension uses the libmemcached library to communicate with the Memcached server.

After reading the definitions of the two extensions, it is becoming more and more interesting. We seem to be getting closer to the truth, but there is only one step left, which is what libmemcached is. Let's continue to think about this question and continue to open the official documentation of Memcached. We can easily find that libmemcached is actually the official client provided by Memcached. In other words, the Memcached extension of PHP is actually a secondary encapsulation extension. This extension stands on the shoulders of the official client extension, so it certainly provides more functions. On the other hand, the Memcache extension is just a set of Memcached extension libraries implemented by PHP itself. Having said that, I believe many PHP programmers should understand why we no longer advocate the use of the Memcache extension. The following figure shows the working principles of the two extensions.

There is also a special extension in PHP

The above analysis shows two extensions. In fact, the situation of these two extensions is not unique in PHP. There is another knowledge point in PHP that is the same as this situation, which is Mysqlnd and libmysqlclient that we are going to talk about next.

Through the previous analysis, it is not difficult to think that libmysqlclient is actually the MySQL programming client officially provided by MySQL database, and Mysqlnd is actually the MySQL programming client implemented by PHP itself. It is not secondary developed based on libmysqlclient, but is written in C language.

In fact, Memcached not only supports PHP, but also supports C, C++, Java, MySQL, Python, Nodejs, etc. Through the above Memcache extension, we know that as long as we follow the protocol it provides, it is easy to implement the Memcached client of your own programming language. Having said so much, I don’t know if you have completely understood the relationship between the two. If you still don’t understand, you can interact in the comments. You can also join the group discussion ( QQ group number 312724475 )

[51CTO original article, please indicate the original author and source as 51CTO.com when reprinting on partner sites]

<<:  The seventh episode of the Aite Tribe Clinic: What function was used to write the King of Pesticide Welfare Bureau?

>>:  Deep learning: preconceptions, limitations, and the future

Recommend

How to get the approval of senior management for SEO implementation plan?

As an SEO for a large company, the most difficult...

The monetization rules of private domain traffic

Private domain traffic belongs to a single indivi...

80txt e-book free download full set

Content preview: [WeChat: jimifeng01] Red|sleeves...

Baidu splash screen advertising industry case

The "imprint effect" in psychology show...

Where did all the discarded RMB go in the end?

One minute with the doctor, the postures are cons...

3 Steps to User Growth Strategy

John has written about some methods of fission be...

Outlook for brand marketing trends in 2022!

During the epidemic, "growth" is less e...

Mante frog: colorful little "poisonous creature"

Cowan's Mantella, scientific name Mantella co...

11 Essential HTML5 Animation Tools

[[155716]] Nowadays, the most popular language in...

Zero-starting teaching: APP first release skills + omni-channel

It is not easy to make a good product APP, but it...