Home > Article > Backend Development > Introduction and working principle of memcached in PHP_PHP tutorial
Introduction to memcached
1. 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, which first served liveJournal. Currently, many people use this caching project to build their own large-load websites to share the pressure on the database. Its working mechanism is to open up a space in the memory and then create a hash table. The main program of memcached manages this hash table by itself
2. Working principle
memcached runs in one or more servers as a daemon, accepting connection operations from multiple clients at any time. Clients can be written in various languages. Currently known client APIs include Perl/php/python/ruby /java/c#/c etc. After the client establishes a connection with the memcached service, the next step is to access objects. Each accessed object has a unique key. Objects saved in memcached are placed in memory rather than in cache files. .
It adopts C/S mode, starts the service process on the server side, specifies the listening IP, its own port number, and the memory size used. The main program of the current version is implemented in C language
3. How to use it in PHP
1. Install PHP’s memcache extension. After installation, you can view the extension configuration information through phpinfo(), and you can change the configuration information in php.ini.
2. Test code:
Copy to ClipboardQuoted content: [www.bkjia.com] $memcache = new Memcache;
References to all the above functions can be found in the PHP Manual