php under the_hood
TRANSCRIPT
![Page 1: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/1.jpg)
PHP under the hoodFrank Neff
![Page 2: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/2.jpg)
PHP
![Page 3: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/3.jpg)
is
![Page 4: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/4.jpg)
compiled
![Page 5: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/5.jpg)
at
![Page 6: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/6.jpg)
runtime!
![Page 7: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/7.jpg)
Source code you write...
![Page 8: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/8.jpg)
…OpCodes you run
![Page 9: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/9.jpg)
Kidding me?
![Page 10: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/10.jpg)
Looks confusing, but this is...
● how PHP works● cool for debugging purposes● visualizing code complexity● helpful trying to understand opcaches like
APC
![Page 11: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/11.jpg)
Try it with your code
http://explain.php.net.so
![Page 12: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/12.jpg)
So this is about profiling?
![Page 13: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/13.jpg)
No! XHProf is about profiling
● XHProf is a function-level hierarchical profiler for PHP
● Reports timing information for every function called
● C-Extension can be loaded via PECL● GUI and libs available
![Page 14: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/14.jpg)
Looks like this
![Page 15: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/15.jpg)
Try it with your code
http://xhprof.io/
![Page 16: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/16.jpg)
![Page 17: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/17.jpg)
Compiling at runtime is slow!
![Page 18: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/18.jpg)
OpCode Cache
● Performance enhancing extension for PHP● Hooking into the execution life-cycle● Caching the results of the compilation phase
for later reuse● APC● XCache
![Page 19: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/19.jpg)
HHVM
● HipHop Virtual Machine● Designed for executing PHP programs● Predecessor HPHPc makes C out of PHP● Uses a just-in-time (JIT) compilation● http://www.hhvm.com/
![Page 20: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/20.jpg)
![Page 21: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/21.jpg)
\Lets\Talk\About\Namespaces
![Page 22: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/22.jpg)
![Page 23: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/23.jpg)
Kidding me?
![Page 24: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/24.jpg)
No!
● Namespaces in PHP are just class-prefixes● They are added to each classname by the
compiler● The result is called a FQCN - Fully Qualified
Class Name
![Page 25: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/25.jpg)
![Page 26: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/26.jpg)
![Page 27: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/27.jpg)
![Page 28: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/28.jpg)
What do you think of copy & paste code?
![Page 29: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/29.jpg)
![Page 30: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/30.jpg)
What do you think of traits?
![Page 31: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/31.jpg)
![Page 32: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/32.jpg)
Cool. Traits are for...
● Code reusage● Multiple inheritance● Keeping stuff you often use in different
contexts● No need for complex OOP architectures
![Page 33: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/33.jpg)
Nooooooo!
![Page 34: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/34.jpg)
Seriously...
![Page 35: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/35.jpg)
No.
![Page 36: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/36.jpg)
No. Because traits are...
● Copied into every single class at compile-time
● Therefore not runtime bindable● Not testable● Tightly coupled● Make it easier to cross SRP (one god-class)
![Page 37: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/37.jpg)
(traits === copy & paste)
![Page 38: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/38.jpg)
Wanna read more?● PHP at the Core: A Hacker's Guide● PHP Compiler Internals● PHP OpCodes● PHP Internals● Are Traits The New Eval?● PHP-RFC’s
![Page 39: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/39.jpg)
So you’re telling me not to use such cool features in PHP?
![Page 40: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/40.jpg)
No.
Just be aware of how things work in PHP while writing code
![Page 41: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/41.jpg)
![Page 42: Php under the_hood](https://reader033.vdocument.in/reader033/viewer/2022060108/554fb630b4c90586258b54ab/html5/thumbnails/42.jpg)
Frank NeffSoftware Engineer
Thankshttp://stickerish.com/http://xhprof.io/http://www.vbulletin.com/http://en.wikipedia.org/http://blog.supermedia.com/http://twitter.com/http://tossfair.wordpress.com/http://juliannb4.deviantart.com/http://www.walldime.com/http://gist.github.comhttp://meanduchicago.wordpress.com/
Images ● @frank_neff
● github.com/frne
● speakerdeck.com/frne
● frankneff.ch
● ymc.ch