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
$array = array();
while($val = $res->fetch())  {
 $array[] = $val;
}
$arr = array_unique($array);

Faster
$array = array();
$dedup = array()
while($val = $res->fetch())  {
  if(isset($dedup[$val])) {
    $dedup[$val] = true;
    $array[] = $val;
  }
}



Other ways

Talk of Xavier De Cock auf der SymfonyLive2010

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki