PHP uses the memcache cache technology to improve the response speed. PHP uses the memcache cache technology to increase the response speed. This article describes how PHP uses the memcache cache technology to increase the response speed. We will share this article with you for your reference how PHP uses the memcache cache technology to increase the response speed.
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.
Example: This article describes how PHP uses the memcache cache technology to increase the response speed. Share it with you for your reference...