複製代碼代碼如下:
$memcachehost = 'localhost';
$meache🎜>$memcachehost = 'localhost';
$meacheache🎜>$memcachehost = '12111 ';
function microtime_float(){
list($usec, $sec) =explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
函數運行時($t1){
回傳number_format((microtime_float() - $t1)*1000, 4).'ms';
}
$starttime = microtime_float ();
$cache_time = '30';
echo "init=====".runtime($starttime).'
';
$sql = "從hx 選擇* WHERE id = 10006";
$mem_sql_key = md5($sql);
$t1 = microtime_float();
echo "APC_read=====";
$arrs = apc_fetch($ mem_sql_key);
回顯運行時($t1).'
';
$t1 = microtime_float();
apc_store($mem_sql_key.'_test', $arrs, $cache_time);
echo "APC_write=====";
回顯運行時($t1).'
';
$t1 = microtime_float();
$mem = 新的Memcache ;
$mem->connect($memcachehost, $memcacheport);
echo "MEM_c
$t1 = microtime_float();
$arrs = $mem->get($mem_sql_key); 🎜>echo "MEM_read=====";
echo運行時($t1).'
';
$t1 = microtime_float();
$mem->set($mem_sql_key .'_test',$arrs,0,$cache_time); 🎜>echo "MEM_write====="
echo runtime($t1).'
';
先把這句話SQL的結果在apc和memcached中都快取了,然後測試讀寫速度。