PHP uses memcache caching techniques to improve response speed, Memcache caching _php Tutorials

Source: Internet
Author: User

PHP uses memcache caching techniques to improve response speed, memcache caching


The example in this paper describes how PHP uses Memcache caching technology to improve response speed. Share to everyone for your reference. The specific analysis is as follows:

Although PHP has been done very quickly, but if the big data volume will still have some cards, here to introduce PHP in the use of Memcache cache technology to improve the response speed method, there is a need to understand the friends can refer to.

Memcache can be used under Linux as well as in Windows, of course, the Linux system, as for how to install memcache,google a bit on everything out.

Here is an example of the use of Memcache, the code is as follows:
Copy CodeThe code is as follows: <?php
Connection
$mem = new Memcache;
$mem->connect ("127.0.0.1", 11211) or Die ("Could not Connect");
Show 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 Array
$arr = Array (' AAA ', ' BBB ', ' CCC ', ' ddd ');
$mem->set (' Key2 ', $arr, 0, 60);
$val 2 = $mem->get (' Key2 ');
echo "Get Key2 value:";
Print_r ($val 2);
echo "
";
Delete data
$mem->delete (' Key1 ');
$val = $mem->get (' Key1 ');
echo "Get Key1 value:". $val. "
";
Clear All data
$mem->flush ();
$val 2 = $mem->get (' Key2 ');
echo "Get Key2 value:";
Print_r ($val 2);
echo "
";
Close connection
$mem->close ();
?>
Example 2, the code is as follows:
Copy CodeThe code is as follows: <?php
Using the Memcache cache
$MC = Memcache_connect (' localhost ', 11211);
$PN = $MC->get (' pid ');
Echo $PN;
if ($pn <1) $PN = 1;
else $PN + +;
$MC->set (' pid ', $PN, 0,0); Settings never expire
Memcache_close ($MC);
?>

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/933605.html www.bkjia.com true http://www.bkjia.com/PHPjc/933605.html techarticle PHP uses memcache caching techniques to improve response speed, Memcache caching This article describes how PHP uses memcache caching techniques to improve responsiveness. Share to everyone for your reference ...

  • Related Article

    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.