Php under the_hood
Upcoming SlideShare
Loading in...5

Php under the_hood






Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Php under the_hood Php under the_hood Presentation Transcript

  • PHP under the hood Frank Neff
  • PHP
  • is
  • compiled
  • at
  • runtime!
  • Source code you write...
  • …OpCodes you run
  • Kidding me?
  • Looks confusing, but this is... ● how PHP works ● cool for debugging purposes ● visualizing code complexity ● helpful trying to understand opcaches like APC
  • Try it with your code
  • So this is about profiling?
  • 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
  • Looks like this
  • Try it with your code
  • Compiling at runtime is slow!
  • 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
  • HHVM ● HipHop Virtual Machine ● Designed for executing PHP programs ● Predecessor HPHPc makes C out of PHP ● Uses a just-in-time (JIT) compilation ●
  • LetsTalkAboutNamespaces
  • Kidding me?
  • 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
  • What do you think of copy & paste code?
  • What do you think of traits?
  • Cool. Traits are for... ● Code reusage ● Multiple inheritance ● Keeping stuff you often use in different contexts ● No need for complex OOP architectures
  • Nooooooo!
  • Seriously...
  • No.
  • 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)
  • (traits === copy & paste)
  • 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
  • So you’re telling me not to use such cool features in PHP?
  • No. Just be aware of how things work in PHP while writing code
  • Frank Neff Software Engineer Thanks Images ● @frank_neff ● ● ● ●