PHP uses the memcache cache technology to improve the response speed. memcache cache _ PHP Tutorial

Source: Internet
Author: User
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...

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.