php under the_hood

42
PHP under the hood Frank Neff

Upload: frankneff

Post on 11-May-2015

115 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Php under the_hood

PHP under the hoodFrank Neff

Page 2: Php under the_hood

PHP

Page 3: Php under the_hood

is

Page 4: Php under the_hood

compiled

Page 5: Php under the_hood

at

Page 6: Php under the_hood

runtime!

Page 7: Php under the_hood

Source code you write...

Page 8: Php under the_hood

…OpCodes you run

Page 9: Php under the_hood

Kidding me?

Page 10: Php under the_hood

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

Try it with your code

http://explain.php.net.so

Page 12: Php under the_hood

So this is about profiling?

Page 13: Php under the_hood

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

Looks like this

Page 15: Php under the_hood

Try it with your code

http://xhprof.io/

Page 16: Php under the_hood
Page 17: Php under the_hood

Compiling at runtime is slow!

Page 18: Php under the_hood

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

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
Page 21: Php under the_hood

\Lets\Talk\About\Namespaces

Page 22: Php under the_hood
Page 23: Php under the_hood

Kidding me?

Page 24: Php under the_hood

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
Page 26: Php under the_hood
Page 27: Php under the_hood
Page 28: Php under the_hood

What do you think of copy & paste code?

Page 29: Php under the_hood
Page 30: Php under the_hood

What do you think of traits?

Page 31: Php under the_hood
Page 32: Php under the_hood

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

Nooooooo!

Page 34: Php under the_hood

Seriously...

Page 35: Php under the_hood

No.

Page 36: Php under the_hood

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

(traits === copy & paste)

Page 39: Php under the_hood

So you’re telling me not to use such cool features in PHP?

Page 40: Php under the_hood

No.

Just be aware of how things work in PHP while writing code

Page 41: Php under the_hood