Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHP under the hood

52034cfb48ca73e13e130f2711ec41f0?s=47 Frank Neff
December 19, 2013

PHP under the hood

A talk with some examples how PHP works internally. There are also some examples how namespaces and traits are compiled and how to profile a PHP app.

Please download pdf to open the links...

52034cfb48ca73e13e130f2711ec41f0?s=128

Frank Neff

December 19, 2013
Tweet

Transcript

  1. PHP under the hood Frank Neff

  2. PHP

  3. is

  4. compiled

  5. at

  6. runtime!

  7. Source code you write...

  8. …OpCodes you run

  9. Kidding me?

  10. Looks confusing, but this is... • how PHP works •

    cool for debugging purposes • visualizing code complexity • helpful trying to understand opcaches like APC
  11. Try it with your code http://explain.php.net.so

  12. So this is about profiling?

  13. 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
  14. Looks like this

  15. Try it with your code http://xhprof.io/

  16. None
  17. Compiling at runtime is slow!

  18. 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
  19. 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/
  20. None
  21. \Lets\Talk\About\Namespaces

  22. None
  23. Kidding me?

  24. 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
  25. None
  26. None
  27. None
  28. What do you think of copy & paste code?

  29. None
  30. What do you think of traits?

  31. None
  32. Cool. Traits are for... • Code reusage • Multiple inheritance

    • Keeping stuff you often use in different contexts • No need for complex OOP architectures
  33. Nooooooo!

  34. Seriously...

  35. No.

  36. 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)
  37. (traits === copy & paste)

  38. 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
  39. So you’re telling me not to use such cool features

    in PHP?
  40. No. Just be aware of how things work in PHP

    while writing code
  41. None
  42. Frank Neff Software Engineer Thanks http://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.com http://meanduchicago.wordpress.com/ Images • @frank_neff • github.com/frne • speakerdeck.com/frne • frankneff.ch • ymc.ch