
function getTimeStamp() {
$timestr = microtime();
$timestrary = explode(' ', $timestr);
$result = intval($timestrary[1])*1000 + intval(floatval($timestrary[0])*1000);
return $result;
}
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$key = 'key';
$value ='value';
$redis->set($key, $value);
apc_store($key, $value, 1);
$begin = getTimeStamp();
for($i = 0 ; $i < 100000 ; $i = $i +1) {
$result = apc_fetch($key);
}
$cost = getTimeStamp() - $begin;
var_dump($cost);
$begin = getTimeStamp();
for($i = 0 ; $i < 100000 ; $i = $i +1) {
$result = $redis->get($key);
}
$cost = getTimeStamp() - $begin;
var_dump($cost);
$redis->close();

extension= apc.so apc.enabled=1 apc.shm_segments=1 apc.shm_size=64M ; apc内存的大小,最后的大小需要乘上segments的数量,所以这里一共为apc分配64M apc.ttl=7200 apc.user_ttl=7200 apc.enable_cli=1 ; 这个如果不开启,则只可以在网页上进行apc操作,不能通过cli进行apc操作
版权声明:本文为博主原创文章,未经博主允许不得转载。
以上就介绍了php apc缓存以及与redis的对比,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号