Memcache can be used either under Linux or in Windows systems, and of course the Linux system.
As for how to install Memcache,google, then everything comes out.
Here is an example of a memcache use:
The code is as follows |
Copy Code |
<?php Connection $mem = new Memcache; $mem->connect ("127.0.0.1", 11211) or die ("could not Connect"); Display version $version = $mem->getversion (); echo "Memcached Server version:". $version. " <br> "; Save data $mem->set (' key1 ', ' This is ', ' 0, 60 '); $val = $mem->get (' Key1 '); echo "Get Key1 Value:". $val. " <br> "; Replace data $mem->replace (' key1 ', ' This is replace value ', 0, 60); $val = $mem->get (' Key1 '); echo "Get Key1 Value:". $val. "<br>"; 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 "<br>"; Delete data $mem->delete (' Key1 '); $val = $mem->get (' Key1 '); echo "Get Key1 Value:". $val. "<br>"; Clear All data $mem->flush (); $val 2 = $mem->get (' Key2 '); echo "Get Key2 value:"; Print_r ($val 2); echo "<br>"; Close connection $mem->close (); ?> |
Example 2:
code is as follows |
copy code |
<?php //using 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);//Set never Expires Memcache_close ($MC) ? |