memcached Introduction
First, the concept
1, memcached
From Wiki:memcache is the name of this project, and memcached is the file name of its server-side main program.
Memcache is a project of danga.com, the first to serve the LiveJournal, many people now use this cache project to build their own heavy-duty web site to share the pressure of the database. Its working mechanism is to create a space in memory, and then build a hash table,memcached the main program to manage this hash table
Second, the principle of work
Memcached runs in one or more servers as a daemon, accepting connections from multiple clients at any time, clients can be written in various languages, and currently known client APIs include PERL/PHP/PYTHON/RUBY/JAVA/C#/C and so on. After the client has established a connection to the Memcached service, the next step is to access the object, each object being accessed has a unique key, and the object saved to the memcached is in memory instead of being saved in the cache file.
It takes the C/S mode, starts the service process on the server side, specifies the listening IP, its own port number, and uses the memory size. The current version of the main program is implemented through the C language
Third, how to use in PHP
1, install PHP memcache extension, after installation through Phpinfo () can view the extension configuration information, you can change these configuration information in php.ini.
2. Test code:
Copy to ClipboardWhat to refer to: [www.bkjia.com] $memcache = new Memcache;
$memcache->connect (' 127.0.0.1 ', 11211) or Die ("Could not Connect");
$version = $memcache->getversion ();
echo "Server ' s version:". $version. " \ n ";
$tmp _object = new StdClass;
$tmp _object->str_attr = ' Test ';
$tmp _object->int_attr = 123;
$memcache->set (' key ', $tmp _object, False, or Die ("Failed-to-save data at the server");
echo "Store data in the cache (data would expire in seconds) \ n";
$get _result = $memcache->get (' key ');
echo "Data from the cache:\n";
Var_dump ($get _result);
?>
References to all of the above functions can be found in the PHP manual
http://www.bkjia.com/PHPjc/364436.html www.bkjia.com true http://www.bkjia.com/PHPjc/364436.html techarticle memcached Introduction, Concept 1, memcached from Wiki:memcache is the name of this project, memcached is its server-side main program file name. Memcache is a project of danga.com, the most ...