php include 跟io流的效率
之前看了,平凡的世界大大的一篇文章 传送门 ,php文件缓存性能测试。很不以为然,include怎么会比io流慢了 ,就算加上序列化,按照常理,include也会稍快一些,但是事实却是是如此! 代码如下
测试io流+序列化
function read_cache($filename) {
??????? if($datas = file_get_contents($filename)){
??????????? return $datas;
??????? }
}
$t1 = gettimeofday();
for ($i = 0; $i ??? $x = read_cache("CacheTest_SerializeData.php");
??? $x_r = unserialize($x);
}
$t2 = gettimeofday();
echo ($t2['sec'] - $t1['sec']) * 1000 + ($t2['usec'] - $t1['usec']) / 1000 . "\n";
测试include
$t1 = gettimeofday();
for ($i = 0; $i ??? include("CacheTest_IncludeData.php");
}
$t2 = gettimeofday();
echo ($t2['sec'] - $t1['sec']) * 1000 + ($t2['usec'] - $t1['usec']) / 1000 . "\n";
结果时间相差1s 但是这中间有一个问题 序列化字符串长度有限制,是基于php数组的限制,所以大存放大量文章内容时这种io+序列化可能达不到预期的需求
相关文章
相关视频
上一篇: 浅析Oracle 11g中对数据列默认值变化的优化
下一篇: SQL Server BCP
推荐阅读
-
php中require跟include的几点区别
-
php中require跟include的区别
-
php基础学习-详解equire(),include(),require_once()跟include_once()的异同
-
PHP中include跟require的区别
-
php基础学习-详解equire(),include(),require_once()跟include_once()的异同
-
php include跟require的区别
-
php include 跟io流的效率
-
php include跟require的区别
-
PHP函数的参数按值传递跟引用传递哪个效率更高
-
php中require跟include的几点区别