php优化分三个部分
1,编码优化
2,Opcode缓存¥本文来源gaodai#ma#com搞@@代~&码网^搞gaodaima代码
3,变量和数据缓存
编码部分
1,字符串连接是使用“,”而不是“.”号
<?php
echo “hi”.”there”.”good”;
echo “hi”,”there”,”good”;
?>
2,字符串包含变量时使用双引号而不是单引号
<?php
$name=”php”
echo ‘hi there is ‘.$name;
echo “hi there ,$name”;
?>
3,优先使用require,而不是require_once
导入php脚本的时候会进行大量的操作状态(stat)调用,因而require比required_once 要快。
4,提前计算循环长度
<?php
$items=array(1,2,3,4,5,6,7,8,9);
for($i=0;$i<count(items);i++)
{
statment;
}
$items=array(1,2,3,4,5,6,7,8,9);
$total=count(items);
for($i=0;$i<$total;i++)
{
statment;
}
?>
5,循环访问数组的时候优先使用foreach,其次是用for和while
6,大文件访问是优先使用file_get_contents()。
7,在定义的类中,如无必要可以使用公共变量,而不是使用方法来操作私用变量。
Opcode缓存
1,APC
2,XCache
3,eAccelerator
变量和数据缓存
1,APC
2,memcached