This article mainly introduces how PHP uses the memcache cache technology to increase the response speed. It analyzes the usage skills of the memcache cache technology in the form of examples and has some reference value, for more information, see
This article mainly introduces how PHP uses the memcache cache technology to increase the response speed. It analyzes the usage skills of the memcache cache technology in the form of examples and has some reference value, for more information, see
This article describes how PHP uses the memcache cache technology to speed up response. Share it with you for your reference. The specific analysis is as follows:
Although php has been doing well and fast, if there is still a bit of data in the case of a large amount of data, here we will introduce how to use memcache Cache Technology in PHP to improve the response speed, for more information, see.
Memcache can be used in both linux and windows systems. Of course, it is the first time to install memcache in linux.
The following is an example of using memcache:
The Code is as follows:
<? Php
// Connection
$ Mem = new Memcache;
$ Mem-> connect ("127.0.0.1", 11211) or die ("cocould not connect ");
// Display version
$ Version = $ mem-> getVersion ();
Echo "Memcached Server version:". $ version ."
";
// Save data
$ Mem-> set ('key1', 'this is first value', 0, 60 );
$ Val = $ mem-> get ('key1 ');
Echo "Get key1 value:". $ val ."
";
// Replace Data
$ Mem-> replace ('key1', 'this is replace value', 0, 60 );
$ Val = $ mem-> get ('key1 ');
Echo "Get key1 value:". $ val ."
";
// Save the Array
$ Arr = array ('aaa', 'bbb ', 'ccc', 'ddd ');
$ Mem-> set ('key2', $ arr, 0, 60 );
$ Val2 = $ mem-> get ('key2 ');
Echo "Get key2 value :";
Print_r ($ val2 );
Echo"
";
// Delete data
$ Mem-> delete ('key1 ');
$ Val = $ mem-> get ('key1 ');
Echo "Get key1 value:". $ val ."
";
// Clear all data
$ Mem-> flush ();
$ Val2 = $ mem-> get ('key2 ');
Echo "Get key2 value :";
Print_r ($ val2 );
Echo"
";
// Close the connection
$ Mem-> close ();
?>
Example 2: the code is as follows:
The Code is as follows:
<? Php
// Use memcache Cache
$ Mc = memcache_connect ("localhost", 11211 );
$ Pn = $ mc-> get ('pid ');
Echo $ pn;
If ($ pn <1) $ pn = 1;
Else $ pn ++;
$ Mc-> set ('pid ', $ pn,); // The setting never expires.
Memcache_close ($ mc );
?>
I hope this article will help you with php programming.