Home > Backend Development > PHP Tutorial > PHP MemCached caching application_PHP tutorial

PHP MemCached caching application_PHP tutorial

WBOY
Release: 2016-07-20 11:08:37
Original
915 people have browsed it

Memcached is a high-performance distributed memory object caching system used in dynamic web applications to reduce database load. It delivers the speed of dynamic, database-driven websites by caching data and objects in memory to reduce the number of database reads. Memcached is based on a hashmap that stores key/value pairs. Its daemon is written in C, but the client can be written in any language

What is memcached? Memcached is a high-performance distributed memory object caching system for dynamic web applications to ease database tutorials load. It delivers the speed of dynamic, database-driven websites by caching data and objects in memory to reduce the number of database reads. Memcached is based on a hashmap that stores key/value pairs. Its daemon is written in C, but the client can be written in any language and communicates with the daemon through the memcached protocol. But it does not provide redundancy (for example, duplicating its hashmap entries); when a server s stops or crashes, all key/value pairs stored on s will be lost. Memcached is developed by danga interactive and is used to improve the access speed of livejournal.com. lj has thousands of dynamic page views per second and 7 million users. Memcached greatly reduces the database load, better allocates resources, and provides faster access.

Common methods of memcache

memcache::add — Add a value, if it already exists, return false
memcache::addserver — Add a server address for use
memcache::close — close a memcache object
memcache::connect — create a memcache object
memcache::debug — control the debugging function
memcache::decrement — modify the value in a saved key Subtraction operation
memcache::delete — delete a key value
memcache::flush — clear all cached data
memcache::get — get a key value
memcache::getextendedstats — get the process pool Running system statistics of all processes in
memcache::getserverstatus — Get the parameters of the running server
memcache::getstats — Return some running statistics of the server
memcache::getversion — Return the version information of the running memcache
memcache::increment — Add the value in a saved key
memcache::pconnect — Create a persistent connection object for memcache
memcache::replace — r to an existing key Perform an overwrite operation
memcache::set — Add a value, and overwrite it if it already exists
memcache::setcompressthreshold — Compress data larger than a certain size
memcache::setserverparams — Run When modifying the parameters of the server

memcache method uses the

code as follows:

$memcache = new memcache;
$memcache-> ;connect('127.0.0.1', 11211) or die("Connection failed");
$memcache->set('name', '张三');
$val = $memcache-> ;get('name');
?>

Note: The complete version of the set method, set (key name, key value, whether to compress, retention time)

The code is as follows :

$memcache = new memcache;
$memcache -> connect('127.0.0.1', 11211) or die("Connection failed");
$memcache -> set('name', array('one','two'));
$val = $memcache->get('name');
print_r($val) ;
$memcache -> close();
?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444867.htmlTechArticleMemcached is a high-performance distributed memory object caching system for dynamic web applications to reduce database load. It reduces the time it takes to read the database by caching data and objects in memory...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template