Phpmemcache and phpmemcached are two clients of the php memcache distributed high-speed cache system. phpmemcache is an old client and phpmemcached is a new and more comprehensive function... php memcache and php memcached are two clients of the php memcache distributed high-speed cache system. php memcache is the old client, and php memcached is a new and more comprehensive replacement of php memcached.
Php memcache is implemented independently using php. it is an old client. In practice, we have found multiple problems, with fewer functions and fewer attributes;
Php memcached is an extension of libmemcached based on native c. It is more comprehensive. we recommend that you replace it with php memcached.
1. Php memcache problems
1.1 distributed problems
By default, php memcache automatically switches the instance, so it sometimes gets old data and the value is erratic.
Questions shared by netizens:
There was a small problem when I was working on a product over the past few days. this was a strange phenomenon. two distributed memcached servers were used for the product, and the number of counters retrieved from one was occasionally incorrect, finally, it is located on the failover mechanism of the php memcache client.
We know that in a memcached distributed environment, a key is allocated to a memcached through hash computing.
If php. memcache in ini. when allow_failover = 1, if a memcached has a problem in a distributed environment, it will automatically try other memcached, and the above problem will occur, therefore, if you want to set allow_failover = 0, the system will directly return a failure if it is not obtained from other mc instances, so as to avoid frequent instance switching when the network or server is abnormal, old data will be retrieved.
1.2 High Concurrency stability issues
Lessons learned from Sina Weibo:
Changing php memcache to php memcached greatly improves the stability of high concurrency;
In addition, there are more functions and more precise error codes.
Twitter cache experience
Multi-layer Cache reduces the impact of some cache nodes being down, and reads and writes are all cache; replace memcached api with libmemcached (which facilitates multi-language access to memcached and makes distributed and other rules consistent ).
1.3 1 second timeout interval cannot be modified
The php memcache Client has a one-second timeout interval that cannot be modified:
Bool Memcache: connect (string $ host [, int $ port [, int $ timeout])
The third parameter can be set to timeout in seconds, but cannot be modified.
The following three methods to modify timeout are not valid:
1.3.1. memcache api Memcache: setServerParams cannot be modified;
1.3.2. modify the memcache source code vi php_memcache.h macro definition;
1.3.3. php. ini: default_socket_timeout = 60 is invalid for this timeout.
2. Comparison between memcache and memcached
The old Php memcache Client has very few attribute settings, and the error code granularity is very coarse, which is difficult to locate after an error and lacks some functions:
There are primarily two clients used with PHP. one is the older, more widespread pecl/memcache and the other is 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 First Release Date (beta) actively Developed Yes External Dependency None libmemcached Automatic IC Key Fixup1 Yes No Append/Prepend No Yes Automatic serialation2 Yes Binary Protocol No Optional CAS No Yes Compression Yes Communication Timeout Connect Only varous Options consisthashent yes Delayed Get No Yes Multi-Get Yes Session Support Yes Set/Get to a specific server No Yes Stores Numerics Converted to Strings Yes // note: 1 pecl/memcache will convert an invalid key into a valid key for you. pecl/memcached will return false when trying to set/get a key that is not valid. 2 You do not have to serialize your objects or arrays before sending them to the set commands. both clients will do
Address:
Reprinted at will, but please attach the article address :-)