Optimizing PHP Code
Diving into zval @ z core.Dough: "Working by reference will usually make you waste memory as it can trigger more easily the copy on write."
Hash Tables: Quick access by key or table traversal. But: Not way to get by value.
Be efficient, optimize tight loops, one line functions.
Highly covered source code (profile your app!).
Use tools
Have a look at the PHP Opcode: Vulcan Logic Dumper (pecl VLD)Profile your apps: XDebug / Zend Debug Profilers.
Zend Op
Kind of the "maschine language" of ZE. OpCode, Op1, Op2, Metas (line n°, handler, result)Live hacking Optimization Example
Slow
Faster
$array = array();
$dedup = array()
while($val = $res->fetch()) {
if(isset($dedup[$val])) {
$dedup[$val] = true;
$array[] = $val;
}
}
$dedup = array()
while($val = $res->fetch()) {
if(isset($dedup[$val])) {
$dedup[$val] = true;
$array[] = $val;
}
}
Other ways
- Use built_in functions (except array_* and in_array())
- Use opcode caching! (APC, eAcc, XCache, Zend Server)
- Use data Caching! (Memcached)
- Optimize your SQL
- Acces your data in batches!
- Create PHP Extensions (HP!)
- Use other implementations: Facebooks HipHop, phc, Quercus, RoadSend PHP
There are no comments on this page. [Add comment]