Download - What the HACK is HHVM?
![Page 1: What the HACK is HHVM?](https://reader036.vdocuments.site/reader036/viewer/2022071815/55a83ad01a28ab17778b4802/html5/thumbnails/1.jpg)
What the HACK is HHVM?Leong Hean Hong
2014-06-06 @ HackerspaceJB
![Page 2: What the HACK is HHVM?](https://reader036.vdocuments.site/reader036/viewer/2022071815/55a83ad01a28ab17778b4802/html5/thumbnails/2.jpg)
About
● Web/mobile developer● Android instructor● Experienced in developing web services● Interest in Linux, web, mobile
![Page 3: What the HACK is HHVM?](https://reader036.vdocuments.site/reader036/viewer/2022071815/55a83ad01a28ab17778b4802/html5/thumbnails/3.jpg)
Agenda
● What is HHVM● Where does HHVM come from?● Why use HHVM?● What is Hack?● Demo (benchmark test)
![Page 4: What the HACK is HHVM?](https://reader036.vdocuments.site/reader036/viewer/2022071815/55a83ad01a28ab17778b4802/html5/thumbnails/4.jpg)
What is HHVM?PHP Code
Hack Code
Zend Engine (Interpreter)
HHVM
HipHop Virtual Machine
● PHP execution engine created by Facebook
● Convert PHP to bytecode● Bytecode translated to machine code
at runtime by JIT (just-in-time) compiler
● Similar to .NET/CLR, Java/JVM
JIT
![Page 5: What the HACK is HHVM?](https://reader036.vdocuments.site/reader036/viewer/2022071815/55a83ad01a28ab17778b4802/html5/thumbnails/5.jpg)
Once upon a time...
● 2008 - Facebook create HPHPc to convert PHP to C++
● Performance boost over Zend PHP● Don’t fully support PHP language● Deployment includes pushing 1GB+ binary
to multiple servers● Need to maintain production+debug builds
![Page 6: What the HACK is HHVM?](https://reader036.vdocuments.site/reader036/viewer/2022071815/55a83ad01a28ab17778b4802/html5/thumbnails/6.jpg)
the story continues...
● 2010 - Facebook decided to build VM for PHP
● HHVM built on top of HPHPc● 2013 - Facebook.com started running on
HHVM, replacing HPHPc
![Page 7: What the HACK is HHVM?](https://reader036.vdocuments.site/reader036/viewer/2022071815/55a83ad01a28ab17778b4802/html5/thumbnails/7.jpg)
Why use HHVM?
● Better performance than Zend PHP● Nearly full compatibility with PHP 5.4● 100% support CI, Drupal, Laravel, PHPUnit,
… (http://hhvm.com/frameworks/)
● Supports Hack
![Page 8: What the HACK is HHVM?](https://reader036.vdocuments.site/reader036/viewer/2022071815/55a83ad01a28ab17778b4802/html5/thumbnails/8.jpg)
Note on using HHVM
● Not available in many Linux repos○ Installation guide: http://bit.ly/1kP9aWS○ Some prebuilt packages provided on GitHub (http:
//bit.ly/1oj3SIK)● Usage with webservers: FastCGI (http://bit.
ly/1xgplGA)● Installation on Mac is unsupported and
experimental (as of 2014-06-06)
![Page 9: What the HACK is HHVM?](https://reader036.vdocuments.site/reader036/viewer/2022071815/55a83ad01a28ab17778b4802/html5/thumbnails/9.jpg)
What is Hack?
● Programming language for HHVM● Can mix PHPSome of the features● Static typing● Generics● Collections: Vector, Map, Set, Pair
![Page 10: What the HACK is HHVM?](https://reader036.vdocuments.site/reader036/viewer/2022071815/55a83ad01a28ab17778b4802/html5/thumbnails/10.jpg)
Type Annotation<?hhclass MyClass { const int MyConst = 0; private string $x = ''; public function increment( int $x): int { $y = $x + 1; return $y; }}
// Source: http://hacklang.org/
![Page 11: What the HACK is HHVM?](https://reader036.vdocuments.site/reader036/viewer/2022071815/55a83ad01a28ab17778b4802/html5/thumbnails/11.jpg)
Generics<?hhclass Box<T> { protected T $data;
public function __construct( T $data) { $this->data = $data; }
public function getData(): T { return $this->data; }}
// Source: http://hacklang.org/
![Page 12: What the HACK is HHVM?](https://reader036.vdocuments.site/reader036/viewer/2022071815/55a83ad01a28ab17778b4802/html5/thumbnails/12.jpg)
Vector<?hh// Hack introduces new collection types (Vector, Set and Map).function test(): int {
// Vector is preferred over array(1, 2, 3) $vector = Vector {1, 2, 3};
$sum = 0; foreach ($vector as $val) { $sum += $val; }
return $sum;}
// Source: http://hacklang.org/tutorial/
![Page 13: What the HACK is HHVM?](https://reader036.vdocuments.site/reader036/viewer/2022071815/55a83ad01a28ab17778b4802/html5/thumbnails/13.jpg)
Demo