Save 37% off PRO during our Black Friday Sale! »

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.

6648bd4390fba79c9baa6045e58fa337?s=128

Benoit Jacquemont

February 23, 2017
Tweet

Transcript

  1. None
  2. What's a PHP Engine? Anything that can run PHP code

  3. Why Creating a PHP Engine?

  4. 1. To Increase Performances

  5. 2. To Attract some parts of the biggest web dev

    ecosystem
  6. Let's go on a trip!

  7. The Civilized Territories

  8. The Zend Engine by official PHP Engine appeared first in

    PHP 4 Zend Engine III for PHP 7
  9. Zend Engine: How it works Execution Time PHP Code ⬇

    compiled to Op Code ▶ executed by Zend VM ▶ executed by Processor
  10. HHVM Hip Hop Virtual Machine by Perfomances = $$$$$$$

  11. HHVM: How it works Execution Time PHP Code ⬇ compiled

    to Op Code ▶ compiled by JIT to Machine Code ▶ executed by Processor
  12. The Binary Compilers Back to the roots!

  13. Roadsend PHP Direct compiler from PHP to native binaries Started

    in 2007, abandonned in 2012 www.roadsend.com
  14. 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
  15. Hip Hop PHP by Performances! Transpile PHP to C++ Superseded

    by HHVM (Hip Hop VM), as not dynamic enough (no eval)
  16. 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
  17. The Perl Lost World

  18. 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
  19. Introducing Perl 6

  20. Building Perl 6 VM

  21. "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
  22. Pipp: Pipp is Parrot's PHP Part of the all dynamic

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

    Parrot Code ▶ executed by Parrot VM ▶ executed by Processor
  24. The Java Land

  25. 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 ✈");
  26. Quercus: How it works Execution Time PHP Code ⬇ transpiled

    to Java Code ▶ compiled by javac to Byte Code ▶ executed by JVM ▶ executed by Processor
  27. 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
  28. JPHP samples: Multithreading $thread = new Thread(function () { $i

    = 0; while (true) { $i++; echo $i, "\n"; sleep(2); // every 2 seconds } }); $thread->start(); // start thread
  29. 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();
  30. 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
  31. None
  32. The Snake Country

  33. HippyVM started at uses (JIT inside) Not actively maintained anymore

  34. HippyVM Performances

  35. HippyVM: How it works Execution Time PHP Code ⬇ transpiled

    by HippyVM to RPython ▶ compiled by PyPy JIT into Machine Code ▶ executed by Processor
  36. MS World

  37. Phalanger "improves the performance, allows to use modern environments ...

    compiles legacy PHP code" Not maintained anymore phalanger.codeplex.com
  38. 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
  39. 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
  40. PeachPie Benchmarks

  41. 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
  42. The Land of the Little Ones

  43. 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
  44. 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');
  45. 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); }
  46. 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
  47. The Rusted Land

  48. Tagua VM Written in Rust Security Focused: Safety First! Benefits

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

    ⬇ compiled to Op Code ▶ executed by Tagua VM ▶ executed by Processor
  50. 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
  51. Conclusion That's a big world out there! The Leaders Zend

    Engine HHVM The Challengers Peache Pie Tagua VM
  52. Thank you! Questions?