How PHP uses memcache cache technology to improve response speed-PHP source code

Source: Internet
Author: User
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);?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.