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 ...