PHP script Operation Memcache Server
First, PHP script operation Memcache Method
Using PHP scripts to manipulate Memcache, in the PHP manual is described in detail, we can instantiate the Memcache class, according to the requirements of the object method. Memcached is more Memcache than
Powerful class library, more features, here only introduce memcache.
Some methods are introduced:
1.memcache::add-Add an entry to the cache server
2.memcache::addserver-Adding a Memcache server to the connection pool
3.memcache::close-Closing the Memcache connection
4.memcache::connect-Open a memcached server connection
5.Memcache::d ecrement-decrements The value of the element
6.Memcache::d elete-Delete an element from the server
7.memcache::flush-Cleaning (deleting) All the elements that have been stored
8.memcache::get-checking back an element from the service side
9.memcache::getextendedstats-all server statistics in the cache server pool
10.memcache::getserverstatus-used to get the online/offline status of a server
11.memcache::getstats-Getting server statistics
13.memcache::increment-increment the value of an element
14.Memcache::p connect-Open a persistent connection to the server (setting to consider access concurrency)
15.memcache::replace-Replace the value of an already existing element
16.memcache::set-store data at the server
17.memcache::setcompressthreshold-turn on large value auto-compression
18.memcache::setserverparams-Modifying server parameters and status at run time
Second, PHP script application Memcache basic ideas (Memcache workflow)
Example: When we need to get user information from a table, we use the URL address (Get) method to request data to the Memcache server. Depending on the operating characteristics of the Memcache server itself, when there is no storage request for the corresponding value
, Memcache will request data to the database, the successful acquisition of the data after the client, but also store a copy within itself, so that the next time the same request, so that the data will be directly from memory, greatly improve the efficiency of requests, reduce the pressure of the database.
1<?PHP2 3 //Instantiate Memcache4 $m=NewMemcache;5 6 //Link Memcache Server7 $m->connect (' localhost ', 11211);8 9 //get a Get valueTen $id=$_get[' ID ']; One A //Defining SQL Structured Statements - $sql= "SELECT * from User WHERE id=".$id; - the //Encryption Processing - $key=MD5($sql); - - //Check if data is stored in Memcache + if(!$m->get ($key)) - { + //instantiate the PDO link database A $pdo=NewPDO (' mysql:host=localhost;dbname=test;charset=utf8;port=3306 ', ' root ', '); at - //Querying Data - $stmt=$pdo->query ($sql); - - //Parse result set - $data=$stmt->fetch (PDO::FETCH_ASSOC); in - //set the data to Memcache to $m->set ($key,$data); + } - the Var_dump($m->get ($key));
PHP Operation Memcache Basic ideas (memcache workflow application)
Memcache Learning Notes (ii)----PHP script Operations Memcache Server