(一) 一个简单的测试 看看php7跑多快(就不罗列电脑配置了,因为环境是一样的)
1 测试代码:
/**
* test.php ; compare php5.6.7 with php7.0.0alphal on time and memory by this simple program
*/
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$time_start = microtime_float();
$memory_start = memory_get_usage();
echo "Time start $time_start\n";
echo "Memory start $memory_start\n";
// Sleep for a while
//usleep(100);
$sum = 0;
for($i=1; $i<=100000000; $i++)
{
$sum+=$i;
}
$i--;
echo "Sum(1+2+3+...+$i) = $sum\n";
$time_end = microtime_float();
$memory_end = memory_get_usage();
echo "Time end $time_end\n";
echo "Memory end $memory_end\n";
$time = $time_end - $time_start;
$memory = $memory_end - $memory_start;
//echo "Did nothing in $time seconds\n";
echo "Sub time $time seconds\n";
echo "Sub momory $memory byte\n";
?>
2 测试结果:
运行速度:php5.6.7用时3.5s,php7用时2.0s,php7在运行速度上有了很大的提升
内存增量:这方面php7优势更明显,php5.6.7内存增量是640byte,而php7的内存增量只有32byte
内存消耗:php7开始时内存使用量要多于php5.6.7,应该是引擎做了更多的预处理工作
(二)兼容问题
1 当给php7安装扩展的时候发现报错 error: ext/standard/php_smart_str.h: No such file or directory
之前给php5.6.7安装这个扩展的时候是没有问题的,于是我搜索了一下
➜ find / -name php_smart_str.h
/usr/local/php/include/php/ext/standard/php_smart_str.h
/usr/local/src/php-5.4.35/ext/standard/php_smart_str.h
/usr/local/src/php-5.6.7/ext/standard/php_smart_str.h
看结果两个源包中都有这个文件 当前安装的php目录里面也有这个文件 但是php7的源包和安装目录中都没有这个文件
➜ ~ ls /usr/local/src/php-5.6.7/ext/standard | grep php_smart_str
php_smart_str.h
php_smart_str_public.h
➜ ~ ls ~/Downloads/php-7.0.0alpha1/ext/standard | grep php_smart_str
php_smart_string.h
php_smart_string_public.h
看这个名字在php7的源码包中有php_smart_string.h这个文件 用Bcompare对比了俩文件 差很多
且不说这个源文件是什么作用,老版本有而php7源包里面没有,这应当算是个兼容性问题
(三)总结 php7在运行速度上确实有了质的飞跃,这是最重要的也是最令人振奋的,据鸟哥说速度已经和hhvm不差了 php7alphal版本在安装扩展的时候非常鸡肋,如果你用到很多扩展,那么还是等正式版本吧