About Memcached

<?php
	//new classs Memcache 
	$oMemcached = new Memcache;
	$oMemcached->connect("localhost","11211") or die("can't connect to localhost");
	$sVersion   = $oMemcached->getVersion();
	//echo "Server's version:".$sVersion;

	$sP1 = "store sth";
	$sP2 = "anthor thing";
	
	//put $sP1 into "key" . active life is 100s.
	if($oMemcached->set("key",$sP1,0,100)){
		echo "Set syntax is work : ".$oMemcached->get("key");
	}else{
		echo "Set syntax isn't working";
	}
	
	echo "<hr>";
	
	//will not active , because "key" has been evaluate.so add syntax don't work
	if($oMemcached->add("key",$sP2,0,100)){
		echo "Add syntax is work : ".$oMemcached->get("key");
	}else{
		echo "Add syntax isn't working";
	}
	
	echo "<hr>";

	//replace syntax is work . it will conver "key" value , now active life is 200s
	if($oMemcached->replace("key",$sP2,0,200)){
		echo "Replace syntax : ".$oMemcached->get("key");
	}else{
		echo "Replace syntax isn't working";
	}

	echo "<hr>";


	if($oMemcached->delete("key1",150)){
		echo "Delete syntax is work :";
	}else{
		echo "Delete syntax isn't working";
	}

	/**
	 * anthor test for increment and decrement
	 */

	echo "<hr>";

?>

1、什麽情況下使用memcache。(緩存技術)

    1.1、數據庫讀出的數據(select)使用memcache  。   

    1.2、在回話控制session中使用。

2、注意。

    2.1、同一項目安裝兩次,key要有前綴。

    2.2、用SQL語句做key。或者MD5加密后的SQL做key。

    2.3、內網訪問memcache,設置防火牆.

3、CMD訪問memcache  " telnet localhost 11211 "

你可能感兴趣的:(PHP,memcached)