memcached php memcached client memcached
The official homepage of memcache: http://pecl.php.net/package/memcache
The official homepage of memcached: http://pecl.php.net/package/memcached
The following is a record of my process of installing the Memcached version of the PHP module :
wget http://download.tangent.org/libmemcached-0.48.tar.gz
tar zxf libmemcached-0.48.tar.gz
cd libmemcached-0.48
./configure --prefix=/usr/local/libmemcached - -with-memcached
make
make install
wget http://pecl.php.net/get/memcached-1.0.2.tgz
tar zxf memcached-1.0.2.tgz
cd memcached-1.0.2
/usr /local/webserver/php/bin/phpize
./configure --enable-memcached --with-php-c/local/webserver/php/bin/php-config --with-libmemcached-dir=/usr/local /libmemcached
make
make install
Add
extension=memcached.so to php.ini
Complete
Another:
When installing libmemcached, if you only use ./configure, you may be prompted:
checking for memcached… no
configure : error: “could not find memcached binary”
The two are almost identical in use.
Copy the code The code is as follows:
$mem = new Memcache;
$mem->addServer($memcachehost, '11211');
$mem->addServer($memcachehost, '11212' ; md = new Memcached;
$servers = array(
array($memcachehost, '11211'),
array($memcachehost, '11212')
$md->addServers($servers);
$md ->set('hx','9enjoy'); echo $md->get('hx'); memcached has many more methods than memcache, such as getMulti, getByKey, addServers, etc.
memcached does not have the connect method of memcache, and it does not currently support long connections.memcached supports Binary Protocol, but memcache does not, which means memcached will have higher performance.
Memcache is implemented natively and supports the coexistence of both OO and non-OO interfaces. memcached uses libmemcached and only supports OO interfaces.
More detailed differences: http://code.google.com/p/memcached/wiki/PHPClientComparison
The memcached server is a centralized caching system, and the distributed implementation method is determined by the client.
Memcached’s distribution algorithm generally has two options:
1. According to the result of hash(key), the remainder of the modular connection number determines which node is stored, that is, hash(key)% sessions.size(). This algorithm is simple and fast ,good performance. However, this algorithm has a shortcoming, that is, when memcached nodes are added or deleted, the original cached data will become invalid on a large scale, and the hit rate will be greatly affected. If there are many nodes and cached data, the cost of rebuilding the cache will be too high, so With the second algorithm.
2. Consistent Hashing, consistent hashing algorithm, its node search process is as follows:
First find the hash value of the memcached server (node), and configure it on the circle (continuum) from 0 to 232. Then use the same method to find the hash value of the key storing the data and map it to the circle. It then searches clockwise starting from the location where the data is mapped, and saves the data to the first server found. If the server is still not found after exceeding 2 to the power of 32, it will be saved to the first memcached server.
memcache uses the first method without any configuration. To implement the first method, memcached seems to use (unconfirmed):
$md->setOption(Memcached::OPT_HASH, Memcached::HASH_CRC);
memcache in php. ini add
Copy code
The code is as follows:
Memcache.hash_strategy =consistent
Memcache.hash_function =crc32
memcached is added to the program (not confirmed)
Copy code The code is as follows :
$md->setOption(Memcached::OPT_DISTRIBUTION, Memcached::DISTRIBUTION_CONSISTENT);
$md->setOption(Memcached::OPT_HASH, Memcached::HASH_CRC);
or
$mem->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE,true);
Some reference documents:
memcached distribution test report (hash function selection in the case of consistent hashing):
http://www.iteye.com/topic/346682
The difference between php module memcache and memcached: http:// www.jb51.net/article/27366.htm
PHP module: Memcached > Memcache: http://www.jb51.net/article/27367.htm
20110509@@UPDATE:
If you install libmemcached, there will be the following error message:
make[2]: *** [clients/ms_conn.o] Error 1
make[2]: Leaving directory `/www/soft/libmemcached-0.48'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/www/soft/libmemcached-0.48'
make: *** [all] Error 2
Can be added when configure --disable-64bit CFLAGS="-O3 -march= i686"
That is: ./configure --prefix=/usr/local/libmemcached --with-memcached --disable-64bit CFLAGS="-O3 -march=i686"
The above introduces memcached, the memcached client of Memcached php, including Memcached content. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Memcached is a commonly used caching technology that can greatly improve the performance of web applications. In PHP, the commonly used Session processing method is to store the Session file on the server's hard disk. However, this method is not optimal because the server's hard disk will become one of the performance bottlenecks. The use of Memcached caching technology can optimize Session processing in PHP and improve the performance of Web applications. Session in PHP

Caching library in PHP8.0: Memcached With the rapid development of the Internet, modern applications require efficient and reliable caching technology to improve performance and handle large amounts of data. Due to PHP's popularity and open source nature, the PHP caching library has become an essential tool in the web development community. Memcached is a widely used open source high-speed memory caching system that can handle millions of simultaneous connected cache requests and can be used in many different types of applications, such as social networks, online

With the development of the Internet, PHP applications have become more and more common in the field of Internet applications. However, high concurrent access by PHP applications can lead to high CPU usage on the server, thus affecting the performance of the application. In order to optimize the performance of PHP applications, Memcached caching technology has become a good choice. This article will introduce how to use Memcached caching technology to optimize the CPU usage of PHP applications. Introduction to Memcached caching technology Memcached is a

With the rapid development of the Internet, large-scale MySQL database backup and recovery has become one of the essential skills for major enterprises and websites. With the widespread application of Memcached, how to back up and restore Memcached has also become an important issue. As one of the main languages for web development, PHP has unique advantages and skills in handling backup and recovery of MySQL and Memcached. This article will introduce in detail the implementation method of PHP processing MySQL and Memcached backup and recovery.

With the continuous increase of network applications and the continuous expansion of data volume, data reading and writing efficiency has become one of the important factors affecting application performance. The application of caching technology can solve this problem well. In PHP applications, Memcached is the most commonly used cache server. Memcached is a high-performance distributed memory object caching system that can store commonly used data in memory and improve the efficiency of data retrieval. This article will introduce how to use PHP and Memcached for cache management, and how to optimize

With the rapid development of modern Internet applications, user experience is crucial to the success of an application. How to ensure high performance and high availability of applications has become one of the important issues that developers need to solve. As one of the widely used programming languages, PHP's performance monitoring and optimization are also very important. Memcached is a high-performance, distributed memory object caching system that can help applications improve performance and scalability. This article will introduce how to use PHP and Memcached to implement performance monitoring.

With the continuous development of Internet technology, audio and video resources have become a very important form of content on the Internet, and PHP, as one of the most widely used languages in network development, is also constantly used in the field of video and audio playback. However, with the increasing number of users of audio and video websites, many websites have discovered a problem: under high concurrency conditions, PHP's processing speed of audio and video slows down significantly, resulting in problems such as inability to play in time or stuck playback. To solve this problem, Memcached caching technology should

With the rapid growth of modern applications, caching has become a vital part of many developers. Caching can greatly improve application performance and reduce server load. In CakePHP, one way to implement caching is to use Memcached. Memcached is a memory-based distributed caching system. It stores data in memory and can read and write data quickly. In a multi-server environment, Memcached can store data in a distributed manner and share it over the network. not only can
