Php ?? Php optimization consists of three parts:
1. encoding optimization
2. Opcode cache
3. variable and data cache
Encoding part
1. the string connection uses "," instead ".".
Echo "hi". "there". "good ";
Echo "hi", "there", "good ";
?>
2. double quotation marks instead of single quotation marks are used when a string contains variables.
$ Name = "php"
Echo 'Hi there is '. $ name;
Echo "hi there, $ name ";
?>
3. use require first, instead of require_once.
When a php script is imported, a large number of operations (stat) are called. therefore, 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. foreach is preferred for loop access to arrays, followed by for and while
6. file_get_contents () is preferred for accessing large files ().
7. You can use public variables unless necessary in the defined class, rather than using methods to operate private variables.
Opcode cache
1, APC
2. XCache
3. eAccelerator
Variable and data cache
1, APC
2, memcached