Memcache is a distributed memory cache system that reduces the load on the database by accessing data and objects in memory, and memcache into the client and server, the server as the C implementation, the ready-made service-side application, the need to configure the server-side listening address and port. , this document records PHP implementation Memcache client
The client to use Memcache cache data, to have two conditions, the first PHP memcache extension to open, you can wamp php->php extension, check Php_memcache, You can also directly modify the php.ini file, will extension=php_memcache.dll before, remove, restart the service, the second condition is that there must be a memcache server
After extracting the Memcache Server installation package to the C:\memcached folder, use the CMD command window to install it.
1> Start > Run: CMD (OK)
2>CD C:\memcached (carriage return)
3>memcached-d Install (enter this step to perform the installation)
4>memcached-d Start (Enter this step to start the Memcache server, default allocation of 64M memory, using 11211 port)
Now that the Memcache server is ready to use, you can use Telnet to access the cache
$ telnet localhost 11211Trying 127.0.0.1Connected to Localhost.localdomain (127.0.0.1). Escape character is ' ^] '. Set foo 0 0 3 (Save command) bar (data) STORED (result) get foo (get command) VALUE Foo 0 3 (data) bar (data)
Memcache Client connection and access is implemented using the original PHP Memcache class, as shown in the code below:
$cache = new Memcache ();
Connecting to the service side
$cache->connect (' localhost ', 11211);
Write cache, last parameter indicates cache expiration time, 0 means never expire, can use flush to clear cache
$cache->set (' aaaaa ', ' wqerqwerqwerqwerwqer ', ', 0);
Read cache
$cache->get (' aaaaa ');
Reference: http://php.net/manual/zh/book.memcache.php
Using Memcache in PHP projects