Home  >  Article  >  Backend Development  >  Memcached PHP module memcache and memcached difference analysis

Memcached PHP module memcache and memcached difference analysis

WBOY
WBOYOriginal
2016-07-29 08:45:321030browse

1. Currently, most PHP environments use the memcache version without d. This version was released earlier and is a native version developed entirely within the PHP framework. The corresponding memcached with d is based on libmemcached, so relatively speaking, the memcached version has more complete functions.
memcache:http://cn2.php.net/manual/en/book.memcache.php
memcached:http://cn2.php.net/manual/en/book.memcached.php
2.Memcache is native It is implemented to support the coexistence of both OO and non-OO interfaces. Memcached uses libmemcached and only supports OO interface.
3. Another very commendable thing about memcached is that the flag is not set during operation, but has a unified setOption(). Memcached implements more of the memcached protocol.
4.memcached supports Binary Protocol, but memcache does not. This means memcached will have higher performance. However, memcached does not currently support long connections.
There is a table below to compare the PHP client extension memcache and memcached
http://code.google.com/p/memcached/wiki/PHPClientComparison
Another point that everyone is more concerned about is the algorithm used. Everyone knows that the "consistent hash algorithm" is an algorithm that has less impact on the data stored on memcached when storage nodes are added or deleted. Then this algorithm can be used in both extension libraries of PHP, but the setting method is different.
Memcache
Modify php.ini and add:
[Memcache]
Memcache.allow_failover = 1


Memcache.hash_strategy =consistent
Memcache.hash_function =crc32


or use ini_ in php set Method:
Ini_set('memcache.hash_strategy','standard');
Ini_set('memcache.hash_function','crc32');
Memcached
$mem = new memcached();
$mem->setOption(Memcached ::OPT_DISTRIBUTION,Memcached::DISTRIBUTION_CONSISTENT);
$mem->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE,true);

The above introduces the analysis of the difference between Memcached php module memcache and memcached, including the content of Memcached. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn