Introduction and working principle of memcached in PHP _php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.