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

The Small World Of PHP Engines

The Small World Of PHP Engines

Every PHP developer know the PHP Engine from Zend, and certainly the one from Facebook HHVM. But did you know that it exists almost a dozen of alternatives PHP engines ?

This talk is a trip around the small world of PHP engines, to discover new horizons from the engines made on JVM to the ones that compile PHP directly to binary, and even an embedded one for IoT.

Benoit Jacquemont

February 23, 2017
Tweet

More Decks by Benoit Jacquemont

Other Decks in Programming

Transcript

  1. Zend Engine: How it works Execution Time PHP Code ⬇

    compiled to Op Code ▶ executed by Zend VM ▶ executed by Processor
  2. HHVM: How it works Execution Time PHP Code ⬇ compiled

    to Op Code ▶ compiled by JIT to Machine Code ▶ executed by Processor
  3. Roadsend PHP Direct compiler from PHP to native binaries Started

    in 2007, abandonned in 2012 www.roadsend.com
  4. Roadsend PHP How it works Compilation Time PHP Code ⬇

    compiled to Machine Code in Native Binaries Execution Time Machine Code from Native Binaries ▶ executed by Processor
  5. Hip Hop PHP by Performances! Transpile PHP to C++ Superseded

    by HHVM (Hip Hop VM), as not dynamic enough (no eval)
  6. Hip Hop PHP How it works Compilation Time PHP Code

    ⬇ transpiled to C++ Code ⬇ compiled to Machine Code in Native Binaries Execution Time Machine Code from Native Binaries ▶ executed by Processor
  7. Perl, What's that? Used to be the most popular language

    for the Web (made CGI popular!) around 2000s System and development oriented Still used a lot as "ops" language apt-get, dpkg rpm
  8. "Parrot is a virtual machine aimed at running all dynamic

    languages." Implementations started for 38 languages, included: Java, Lua, Brainfuck, C, Python, Ruby, Perl 6, .... , PHP Proudly still in development since 2000 www.parrot.org
  9. Pipp: Pipp is Parrot's PHP Part of the all dynamic

    languages effort Last commit: 8 years ago github.com/bschmalhofer/pipp
  10. How Pipp works Execution Time PHP Code ⬇ compiled to

    Parrot Code ▶ executed by Parrot VM ▶ executed by Processor
  11. Quercus "So using PHP with Grails is a quick and

    painless endeavor." Java class usage and Unicode compliance provide Zend standard exts (cURL, PDO, ...) One of the rare alt PHP Engine able to run full applications (Drupal, Wikimedia) Unfortunately, not actively maintained quercus.caucho.com $string = new java.lang.StringBuffer("Unicode string ✈");
  12. Quercus: How it works Execution Time PHP Code ⬇ transpiled

    to Java Code ▶ compiled by javac to Byte Code ▶ executed by JVM ▶ executed by Processor
  13. JPHP Benefits properly from the JVM JIT Debug via the

    xdebug protocol 1.1x faster than PHP 7 Wants to allow PHP on Android Don't provide Zend standard exts Active but not a lot of contributors
  14. JPHP samples: Multithreading $thread = new Thread(function () { $i

    = 0; while (true) { $i++; echo $i, "\n"; sleep(2); // every 2 seconds } }); $thread->start(); // start thread
  15. JPHP samples: UI $form = new UIForm(); $form->size = [600,

    300]; $form->title = 'My Program'; $button = new UIButton(); $button->text = 'Click Me'; $button->on('click', function(MouseEvent $e) { UIDialog::message('Hello World'); }); $form->add($button); $form->show();
  16. JPHP How it works Compilation Time PHP Code ⬇ compiled

    to Byte Code Execution Time Byte Code ⬇ compiled by JIT to Machine Code ▶ executed by Processor
  17. HippyVM: How it works Execution Time PHP Code ⬇ transpiled

    by HippyVM to RPython ▶ compiled by PyPy JIT into Machine Code ▶ executed by Processor
  18. Phalanger "improves the performance, allows to use modern environments ...

    compiles legacy PHP code" Not maintained anymore phalanger.codeplex.com
  19. Phalanger: how it works Compilation Time PHP Code ⬇ compiled

    to Common Intermediary Language Execution Time Common Intermediary Language Code ⬇ compiled by .Net JIT to Machine Code ▶ executed by Processor
  20. PeachPie Superseds Phalanger Benefits from the Roslyn compiler platform Target

    PHP 7.1 syntax First item in the FAQ:"PHP sucks, why port this horrendous language to .NET?" www.peachpie.io
  21. PeachPie: how it works Compilation Time PHP Code ⬇ compiled

    to Common Intermediary Language Execution Time Common Intermediary Language Code ⬇ compiled by .Net JIT to Machine Code ▶ executed by Processor
  22. PH7 - The Embedded PHP Engine Build for real embedded

    hardware Embedded VM similar to Zend VM Dedicated to IoT and home routers ph7.symisc.net
  23. PH7 - Distinctive Features Full type hinting Native UTF-8 support.

    Function arguments can take any complex expressions as their default values. "Correct and consistent implementation of the ternary operator." echo (true?'true':false?'t':'f');
  24. PH7 code sample #define PHP_PROG "<?php "\ "echo 'Welcome guest'.PHP_EOL;"\

    "echo 'Current system time is: '.date('Y-m-d H:i:s').PHP_EOL;"\ "echo 'and you are running '.php_uname();?>" #include <stdio.h> #include <stdlib.h> #include "ph7.h" int main(void) { ph7 *pEngine; ph7_vm *pVm; ph7_init(&pEngine); ph7_compile_v2(pEngine, PHP_PROG, -1 &pVm, 0); ph7_vm_exec(pVm,0); }
  25. PH7 - How it works Compilation Time C code with

    PHP code inside ⬇ compiled to Machine Code with PHP code inside Execution Time Machine code with PHP Code inside ⬇ PHP code compiled to Op Code ▶ executed by Embedded VM ▶ executed by Processor
  26. Tagua VM Written in Rust Security Focused: Safety First! Benefits

    from the LLVM platform github.com/tagua-vm/tagua-vm
  27. Tagua VM - How it works Execution Time PHP Code

    ⬇ compiled to Op Code ▶ executed by Tagua VM ▶ executed by Processor
  28. The Future? JIT on Zend Engine Implemented as part of

    opcache Uses LLVM as backend github.com/zendtech/php-src/tree/zend- jit/ext/opcache/jit
  29. Conclusion That's a big world out there! The Leaders Zend

    Engine HHVM The Challengers Peache Pie Tagua VM