复制代码 代码如下:
$memcachehost = 'localhost';
$memcacheport = '11211';
function microtime_float(){
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
function runtime($t1){
return number_format((microtime_float() - $t1)*1000, 4).'ms';
}
$starttime = microtime_float();
$cache_time = '30';
echo "init=====".runtime($starttime).'
';
$sql = "SELECT * FROM hx WHERE id = 10006";
$mem_sql_key = md5($sql);
$t1 = microtime_float();
echo "APC_read=====";
$arrs = apc_fetch($mem_sql_key);
echo runtime($t1).'
';
$t1 = microtime_float();
apc_store($mem_sql_key.'_test', $arrs, $cache_time);
echo "APC_write=====";
echo runtime($t1).'
';
$t1 = microtime_float();
$mem = new Memcache;
$mem->connect($memcachehost, $memcacheport);
echo "MEM_connet=====".runtime($t1).'
';
$t1 = microtime_float();
$arrs = $mem->get($mem_sql_key);
echo "MEM_read=====";
echo runtime($t1).'
';
$t1 = microtime_float();
$mem->set($mem_sql_key.'_test',$arrs,0,$cache_time);
echo "MEM_write=====";
echo runtime($t1).'
';
?>