PHP optimization is divided into three parts
1, encoding optimization
2,opcode Cache
3, variables and data caching
Coding section
1, the string connection is using "," instead of "." No.
echo "HI". " There "." Good ";
echo "HI", "there", "good";
?>
2, string contains variable when using double quotation marks instead of single quotation mark
$name = "PHP"
Echo ' Hi there is '. $name;
echo "Hi there, $name";
?>
3, prefer to use require instead of require_once
A large number of operation State (STAT) calls are made when the PHP script is imported, so require is faster than required_once.
4, calculate the cycle length in advance
$items =array (1,2,3,4,5,6,7,8,9);
for ($i =0; $i<>< p=""> <>
{
statment;
}
$items =array (1,2,3,4,5,6,7,8,9);
$total =count (items);
for ($i =0; $i < $total; i++)
{
statment;
}
?>
5, when iterating over the array, use foreach first, followed by the For and while
6, large file access is preferred using file_get_contents ().
7, in a defined class, you can use a public variable without using a method to manipulate a private variable, if it is not necessary.
OpCode cache
1,apc
2,xcache
3,eaccelerator
Variables and data caching
1,apc
2,memcached