derick rethans-php secrets

33
Welcome! php|tek - Chicago, US Derick Rethans - [email protected] http://derickrethans.nl/talks.php

Transcript of derick rethans-php secrets

Page 1: derick rethans-php secrets

Welcome!

php|tek - Chicago, USDerick Rethans - [email protected]

http://derickrethans.nl/talks.php

Page 2: derick rethans-php secrets

About Me

● Dutchman living in Norway● eZ Systems A.S.● eZ Components project lead● PHP development● mcrypt, input_filter, date/time support, unicode● QA

Page 3: derick rethans-php secrets

Introduction

Page 4: derick rethans-php secrets

Parsing

● Lexical analyze script source● Divide into logical blocks of characters● Give special blocks a meaning● flex (but only 2.5.4!)

The Parse Error:Parse error: parse error,unexpected T_CLASS, expecting ',' or ';' in - on line 2

Page 5: derick rethans-php secrets

CompilingDiagram

Page 6: derick rethans-php secrets

Compiling: Example

fibonacci.php:<?php $cache = array();

function fibonacci($nr) { global $cache;

if (isset($cache[$nr])) { return $cache[$nr]; } switch ($nr) { case 0: die("Invalid Nr\n"); case 1: return 1; case 2: return 1; default: $r = fibonacci($nr - 2) + fibonacci($nr - 1); $cache[$nr] = $r; return $r; } }

echo fibonacci($argv[1])."\n";?>

Page 7: derick rethans-php secrets

CompilingBreak-down

Page 8: derick rethans-php secrets

CompilingDisassembler

Disassembler: vldDumps oparray per element:

● main script● function● class method

Usage:cvs -d :pserver:[email protected]:/repository login# passwd = srmreadcvs -d :pserver:[email protected]:/repository co -d vld vlecd vldphpize && make && make installphp -dextension=vld.so -dvld.active=1 script.php

Page 9: derick rethans-php secrets

Executing: Diagram

Page 10: derick rethans-php secrets

ExecutingIn a diagram

Page 11: derick rethans-php secrets

Micro-optimizations

print vs. echo

$i++ vs. ++$i

single quotes vs. double quotes

${0}

Page 12: derick rethans-php secrets

Faster Harder Stronger

2003

Page 13: derick rethans-php secrets

PHP Benchmarks

http://sebastian-bergmann.de/archives/634-PHP-GCC-ICC-Benchmark.html

Page 14: derick rethans-php secrets

ExecutingIn a diagram

Page 15: derick rethans-php secrets

Compiler CachesHow it works

● In general, each source file is compiled once● Compilation overhead becomes inconsequential● Cache introduces its own overhead due to dynamic

nature of includes

Page 16: derick rethans-php secrets

Compiler CachesSerialization

● Serialization into SHM● Direct execution from SHM (mostly)

Page 17: derick rethans-php secrets

PHP Accelerators

● APC: active development, PHP license● eAcclerator: GPL● PHP Accelerator: updated, but not improved● Turck MM Cache: abandonned● XCache: new● Zend Platform: commercial

Page 18: derick rethans-php secrets

CompilingConditional functions

Page 19: derick rethans-php secrets

Demo

demo

Page 20: derick rethans-php secrets

Inclued

Dumps includes/classes hiearchiesDownload from http://t3.dotgnu.info/blog/tags/inclued/Install:tar -xvzf inclued-0.3.tgzcd incluedphpize && make && make install

Add to php.ini:extension=inclued.soinclued.enabled=1inclued.dumpdir=/tmp

Page 21: derick rethans-php secrets

Demo

demo

Page 22: derick rethans-php secrets

VariablesThe Symbol Table

Page 23: derick rethans-php secrets

VariablesIntroducing Refcounting

Page 24: derick rethans-php secrets

VariablesRefcounting and Passing Variables to Functions

Page 25: derick rethans-php secrets

VariablesIntroducing References

Page 26: derick rethans-php secrets

VariablesMixing Assign-By Value and Assign-by Reference

Page 27: derick rethans-php secrets

VariablesMixing Assign-by Reference and Assign-by Value

Page 28: derick rethans-php secrets

VariablesPassing by Reference

Page 29: derick rethans-php secrets

VariablesReturn by Reference

Page 30: derick rethans-php secrets

VariablesObjects in PHP 5

Page 31: derick rethans-php secrets

VariablesCircular References

Page 32: derick rethans-php secrets

Questions

?

Page 33: derick rethans-php secrets

Resources

These Slides: http://derickrethans.nl/talks.phpVLD: http://www.derickrethans.nl/vld.phpXdebug: http://xdebug.orgInclued: http://t3.dotgnu.info/blog/tags/inclued/

PHP: http://www.php.net