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

HHVM? Huh?

HHVM? Huh?

An introduction to what HHVM is, how it works, and how to use it.

geevcookie

April 10, 2014
Tweet

More Decks by geevcookie

Other Decks in Programming

Transcript

  1. » Facebook had the "problem" of being too busy »

    Hip Hop Compiler (hphpc) » Compiles PHP to C++
  2. » Facebook had the "problem" of being too busy »

    Hip Hop Compiler (hphpc) » Compiles PHP to C++ » Hip Hop Virtual Machine (HHVM)
  3. » Facebook had the "problem" of being too busy »

    Hip Hop Compiler (hphpc) » Compiles PHP to C++ » Hip Hop Virtual Machine (HHVM) » JIT (Just In Time) Compiler
  4. » Complete custom implementation of PHP » Can act as

    server or run on Apache with FCGI
  5. » Complete custom implementation of PHP » Can act as

    server or run on Apache with FCGI » Can also run from command line
  6. » Complete custom implementation of PHP » Can act as

    server or run on Apache with FCGI » Can also run from command line alias composer='hhvm /usr/local/bin/composer'
  7. » Compiles PHP to HHVM bytecode » Easier to translate

    to native code » Can be interpreted by CPU
  8. » Compiles PHP to HHVM bytecode » Easier to translate

    to native code » Can be interpreted by CPU » Cache implemented as SQLite DB on disk
  9. » 100% compatibility with 18 of the most popular frameworks/libraries

    » Average compatibility of 97.49% » List checked: assetic,codeigniter,composer,doctrine2, drupal,facebookphpsdk,guzzle,idiorm,joo mla,joomlacms,klein,kohana,laravel,mage nto2,mediawiki,mockery,monolog,mustache ,paris,pear,phpbb3,phpmyadmin,phpunit,p roxymanager,ratcher,reactphp,silverstri pe,slim,symfony,twig,vfsstream,yii,zf2
  10. Daemon Config VirtualHost { * { Pattern = .* RewriteRules

    { dirindex { pattern = ^/(.*)/$ to = $1/index.php qsa = true } } } }
  11. FCGI: Apache cd /path/to/your/apache/conf ln -s ../mods-available/mod_proxy.load mods-enabled/mod_proxy.load ln -s

    ../mods-available/mod_proxy.conf mods-enabled/mod_proxy.conf ln -s ../mods-available/mod_proxy_fcgi.load mods-enabled/mod_proxy_fcgi.load httpd.conf ProxyPass / fcgi://127.0.0.1:9000/path/to/your/www/root/goes/here/ VirtualHost ProxyPassMatch ^/(.*.php(/.*)?)$ fcgi://127.0.0.1:9000/path/to/your/www/root/goes/here/$1
  12. Hack: Example <?hh class AnnotatedClass { public int $x; private

    string $s; protected array $arr; public AnotherClass $ac; function bar(string $str, bool $b): float { if ($b && $str === "Hi") { return 3.2; } return 0.3; } }
  13. » Easy to move over to hack as it is

    basically PHP with type annotations
  14. » Easy to move over to hack as it is

    basically PHP with type annotations » Contains new collections (Vector, Set, Map, etc)
  15. » Easy to move over to hack as it is

    basically PHP with type annotations » Contains new collections (Vector, Set, Map, etc) » Contains new Special-Cased functions
  16. » Easy to move over to hack as it is

    basically PHP with type annotations » Contains new collections (Vector, Set, Map, etc) » Contains new Special-Cased functions » invariant, invariant_violation, invariant_callback_register, fun, class_meth, inst_meth, meth_caller
  17. Hack: invariant <?hh function int_not_null(?int $x): int { // Calls

    invariant_violation which in turn throws an exception. invariant($x !== null, 'Cannot work with a null int'); return $x; }
  18. Hack: fun <?hh function f(string $s): void {} function test():

    void { // Will fail. $f = 'f'; $f(1); // Will find get valid callable for function, but will produce a type error. $f = fun('f'); $f(1); }