Memcached is a distributed cache system that was originally developed by Danga Interactive for LiveJournal, but is currently used by many software (such as MediaWiki). This is a set of open source software, released with BSD license authorization.
Memcached lacks authentication and security controls, which means that the memcached server should be placed behind a firewall.
The Memcached API uses a 32-bit cyclic redundancy check (CRC-32) to compute the key values and scatter the data on different machines. When the table is full, the new data will be replaced with the LRU mechanism. Because memcached is often used only as a cache system, applications using memcached need additional code to update information in memcached when writing back to a slower system (like a backend database).
Linux installed memcached after the use of the time is actually very convenient
The code is as follows |
Copy Code |
$array =array (' username ' => ' Zhaoya ', ' passwd ' =>md5 (' Zhaoya ')); $memcache =new memcache (); $memcache->connect (' 127.0.0.1:11211 '); $memcache->set (' list ', $array); $list = $memcache->get (' list '); Print_r ($list); |
Memcache installation under Windows:
1. Download the memcache Windows stable version, extract and put under a certain disk, such as in c:memcached
2. Enter ' c:memcachedmemcached.exe-d install ' installation at terminal (also known as cmd Command interface)
3. Re-enter: ' c:memcachedmemcached.exe-d start ' start. Note: Later memcached will start automatically every time a service is powered on as windows. This way the server side is already installed.
4. Download Php_memcache.dll, please find the corresponding PHP version of the file
5. Join a line of ' Extension=php_memcache.dll ' in C:winntphp.ini
6. Restart Apache, then check phpinfo, if there is memcache, then the installation is successful!
Basic Settings for memcached:
Run the following PHP file, if the output is a test!, it means that the environment has been built successfully. Start to appreciate the charm of memcache!
The code is as follows |
Copy Code |
< PHP $mem = new Memcache; $mem->connect ("127.0.0.1", 11211); $mem->set (' key ', ' This is a test! ', 0, 60); $val = $mem->get (' key '); Echo $val; ?> |
Remind
memcached Start Parameter Description:
-D: Start a daemon,
-M: The amount of memory allocated to Memcache, in megabytes, by default 64MB,
-U: Users running Memcache
-L: Server IP address listening
-P: Set memcache listening port, default is 11211 Note:-P (p is lowercase)
-C: Set maximum number of concurrent connections, default is 1024
-P: Set the PID file to save Memcache note:-P (P is uppercase)
If you want to end the memcache process, execute: Kill cat pid File path