derick rethans-php secrets
TRANSCRIPT
![Page 2: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/2.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/3.jpg)
Introduction
![Page 4: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/4.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/5.jpg)
CompilingDiagram
![Page 6: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/6.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/7.jpg)
CompilingBreak-down
![Page 8: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/8.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/9.jpg)
Executing: Diagram
![Page 10: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/10.jpg)
ExecutingIn a diagram
![Page 11: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/11.jpg)
Micro-optimizations
print vs. echo
$i++ vs. ++$i
single quotes vs. double quotes
${0}
![Page 12: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/12.jpg)
Faster Harder Stronger
2003
![Page 13: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/13.jpg)
PHP Benchmarks
http://sebastian-bergmann.de/archives/634-PHP-GCC-ICC-Benchmark.html
![Page 14: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/14.jpg)
ExecutingIn a diagram
![Page 15: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/15.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/16.jpg)
Compiler CachesSerialization
● Serialization into SHM● Direct execution from SHM (mostly)
![Page 17: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/17.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/18.jpg)
CompilingConditional functions
![Page 19: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/19.jpg)
Demo
demo
![Page 20: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/20.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/21.jpg)
Demo
demo
![Page 22: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/22.jpg)
VariablesThe Symbol Table
![Page 23: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/23.jpg)
VariablesIntroducing Refcounting
![Page 24: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/24.jpg)
VariablesRefcounting and Passing Variables to Functions
![Page 25: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/25.jpg)
VariablesIntroducing References
![Page 26: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/26.jpg)
VariablesMixing Assign-By Value and Assign-by Reference
![Page 27: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/27.jpg)
VariablesMixing Assign-by Reference and Assign-by Value
![Page 28: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/28.jpg)
VariablesPassing by Reference
![Page 29: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/29.jpg)
VariablesReturn by Reference
![Page 30: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/30.jpg)
VariablesObjects in PHP 5
![Page 31: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/31.jpg)
VariablesCircular References
![Page 32: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/32.jpg)
Questions
?
![Page 33: derick rethans-php secrets](https://reader034.vdocuments.us/reader034/viewer/2022051312/546480e9af795979338b493a/html5/thumbnails/33.jpg)
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