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 about how PHP uses the memcache cache technology to speed up response, see the example in this article. 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:
Connect ("127.0.0.1", 11211) or die ("cocould not connect"); // Display version $ version = $ mem-> getVersion (); echo "Memcached Server version: ". $ version."
"; // Save the 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:
Get ('pid '); echo $ pn; if ($ pn <1) $ pn = 1; else $ pn ++; $ mc-> set ('pid ', $ pn,); // Set memcache_close ($ mc);?>