Home >Backend Development >PHP Tutorial >PHP apc cache and comparison with redis
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操作
Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above introduces the PHP apc cache and the comparison with redis, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.