Memcache and memcached two PECL libraries on PHP

Source: Internet
Author: User

When I checked PHP manual, I found that there is one memcache and two memcached PECL libraries in PHP manual, but I don't know the difference between them.

Today, I am not very busy. I searched the internet and found that it was two different PECL libraries. For details, see the following: (I would like to thank the original author for his selfless dedication and gratitude)

Address: http://www.jb51.net/article/22776.htm

At the beginning, I was wondering why there were two libraries, and there were official documentation support in php.net.

I tried to use memcache before. Later I found that memcached supports the setmulti method and is ready to switch to the memcached library.

(I tried it. In fact, memcache supports multi-value set, but it does not exist in the document. It seems that changelog is supported by MySQL 3.0. This function may not be available in the stable version .)

As for efficiency, it is not clear how big the gap will be.

Here is an articleArticleIt is also said that memcached is based on libmemcached and may be better.

 

Finally, the libmemached-based PHP extension was released in PECL.

So now there are two memcache clients on PECL. One is memcache developed completely within the PHP framework, and the other is memecached using libmemcached.

I have never seen libmemcached, but theoretically, libmemcached, which is already popular in other languages, should have better functions. WhileProgramPerformance (memory and CPU usage), although PECL: memcache is native, libmemcached's PECL: memached only supports the OO interface, and PECL :: memcache uses both Oo and non-oo interfaces, dragging it down.

In fact, these are not the most important. Libmemcached has an obvious advantage, that is, with the improvement on the memcached server end, this lib will be followed up immediately. PECL: memcache may not be able to follow up on time.

PECL: memcached. It is also very commendable that the flag is not set during the operation. Instead, there is a unified setoption (). This method is worth transferring from PECL: memcache to PECL: memcached. Specific interface can see here: http://cvs.php.net/viewvc.cgi/pecl/memcached/memcached-api.php? View = Markup

I mentioned in PECL-dev @ whether it can be made into a driver-based architecture. Like MySQL, you can use mysqlnd or libmysql as the underlying engine. However, I don't really support this architecture for memcached. It is different from MySQL.

Mysqlnd is developed as an engine rather than a new API, so that a large number of applications can use the new engine without modifying database operations. If mysqlnd is used as a new extension, it is difficult to choose if it wants to be compatible with previous programs. So far, there are three official MySQL class sets that use libmysql and have different external interfaces. If mysqlnd is compatible with MySQL, it cannot be compatible with mysqli or PDO. Of course, for programs that use their own abstract database classes, this can be achieved by rewriting classes or replacing the driver (PhP Layer. But think about it. Even if we use abstract databases, so many database abstract libraries in the world, if we want everyone to use the nd, we need to change the number of databases and the number of drivers.

Memcached is much simpler. Currently, only PECL: memcache is closely related to the official website, and the interfaces are basically based on the memcached protocol, which is almost the same as libmemcache. They can all be seen as different drivers in an abstract class. So although there are two sets of different clients, there is almost no need to make any changes after they are changed. You only need to change the settings in the class initialization, set/get, and so on, unless you use non-oo interfaces.

In addition, MySQL is more complex in communication and data acquisition than memcache, AND Nd can do something that libmysql cannot do. For example, the buffer can be directly stored using hashtable and zval in PHP; for example, some structures that serve as persistent links can be cached more. (These are just my guesses. I have not read mysqlnd'sCode)

Memcached manual:

Http://cn.php.net/manual/en/book.memcached.php

Memcache manual:

Http://cn.php.net/manual/en/book.memcache.php

Memcached Protocol Comparison between Chinese and English

original address: http://www.jb51.net/article/22776.htm

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.