PHP memcache and PHP memcached comparisons and issues

Source: Internet
Author: User
Tags error code ini memcached php memcached

PHP memcache independent PHP Implementation, is the old client, from our practice has found that there are many problems, and less function, attributes can also be set less;
PHP memcached is based on the libmemcached extension of native C, more perfect, it is recommended to replace the PHP memcached.

1. Problems with PHP Memcache

1.1 Distributed problems
PHP memcache automatically switches the instance by default, so sometimes the old data is fetched and the value is erratic.
The question that the Netizen shares:
These days to do a product when a small problem, the phenomenon is more bizarre, the product used two distributed memcached server. The number of times a counter gets back is occasionally wrong, and finally positioned on the failover mechanism of PHP memcache client.
We know that in a memcached distributed environment, a key is assigned to a memcached by hash calculation.
If the php.ini inside Memcache.allow_failover = 1, in a distributed environment, a memcached problem, will automatically to other memcached try, will appear above the problem. So to set allow_failover = 0 so that you can not get the return failure directly and will not be taken from other MC, so as to avoid network anomalies or server-side exceptions, often switch instances, will take old data.

1.2 High concurrent stability problem
The lessons that Sina Weibo mentions:
PHP memcache to PHP memcached, in high concurrency under the stability of greatly improved;
In addition, more features, error code more accurate.

Twitter's caching experience
Multi-level cache, reduce the impact of some cache nodes after the outage, read and write cache;
The Memcached API is unified for libmemcached (easy multilingual access memcached, so that the rules of distributed and so on are consistent. )

1.3 1 seconds Timeout interval cannot modify the problem
The PHP memcache client has a 1-second timeout interval that does not modify the problem:
BOOL Memcache::connect (string $host [, int $port [, int $timeout]])
The third parameter could have been set to timeout, in seconds, but could not be modified.
The following three ways to modify timeout are not valid:
1.3.1. Memcache API Memcache::setserverparams cannot be modified;
1.3.2. Change Memcache Source code VI php_memcache.h macro definition can not be modified;
This configuration in 1.3.3. php.ini: Default_socket_timeout = 60 is not valid for this timeout.

2. Comparison between Memcache and memcached

PHP memcache This old client can be set in terms of property settings very little;
Error code granularity is very coarse, difficult to locate after the error;
And it lacks some of the features:
There are primarily two clients with PHP. One is the older, and the widespread pecl/memcache and the other are the newer, less used, more feature rich pecl/memcached.
Both support the basics such as multiple servers, setting vaules, getting values, increment, decrement and getting stats.

Here are some more advanced features and information.
Project Pecl/memcache pecl/memcached
Release Date 2004-06-08 2009-01-29 (Beta)
Actively developed Yes
External Dependency None libmemcached
Automatic Key Fixup1 Yes No
Append/prepend No Yes
Automatic Serialzation2 Yes
Binary Protocol No Optional
CAS No Yes
Compression Yes Yes
Communication Timeout Connect only various Options
Consistent hashing Yes
Delayed Get No Yes
Multi-get Yes Yes
Session Support Yes
Set/get to a specific server No Yes
Stores Numerics converted to Strings Yes

Comments:

1 Pecl/memcache'll convert an invalid key to a valid key for you. Pecl/memcached'll return False when trying to set/get a key, not valid.
2 You don't have to serialize your objects or arrays before sending to the set them. Both clients'll do

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.