HHVM is an open-source virtual machine designed for executing programs written in Hack and PHP. HHVM uses a just-in-time (JIT) compilation approach to achieve superior performance for PHP applications.

During these last past months, HHVM and the upcoming PHP 7 version have engaged in an epic battle to become the fastest PHP engine. At Symfony we are thrilled because this fierce competition will ultimately benefit all of us.

Our HHVM compatibility journey started on December 2013, when Joseph Bielawski added HHVM to the list of tested PHP engines on Travis CI (see commit). Shortly after, Fabien made the first code change to improve HHVM compatibility:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Add support for HHVM in the getting of the PHP executable
// @see https://github.com/symfony/symfony/pull/9882

class PhpExecutableFinder
{
    // ...

    public function find()
    {
        if (defined('HHVM_VERSION') && false !== $hhvm = getenv('PHP_BINARY')) {
            return $hhvm;
        }

        // ...
    }
}

That was the first code change, but tens of other changes followed. Some of them were tricky, like the one solved by Christophe Coevoet in the 10,000th Symfony Pull Request:

1
2
3
4
5
6
7
8
9
10
// src/Symfony/Component/Console/Application.php

// HHVM only accepts 32 bits integer in str_split, even when PHP_INT_MAX is
// a 64 bit integer: https://github.com/facebook/hhvm/issues/1327
$width = $this->getTerminalWidth()
    ? $this->getTerminalWidth() - 1
    : (defined('HHVM_VERSION')
        ? 1 << 31
        : PHP_INT_MAX)
    ;

The hard work made by the Symfony Community always put us at more than 99% HHVM compatibility according to their project compatibility charts. The last needed push to achieve the 100% milestone for Symfony 2.3 was led by Nicolas Grekas in the PR 15,146

This last pull request fixed all the issues found on the Debug, DependencyInjection, Filesystem, Form, HttpFoundation, Process and Routing components. However, due to some HHVM issues or lacking PHP features, in some cases our only choice was to skip the test entirely:

1
2
3
if (defined('HHVM_VERSION')) {
    $this->markTestSkipped('HHVM behaves differently in this test case.');
}

After these changes were merged, Travis finally displayed a green result for Symfony 2.3 tests run on HHVM:

Symfony 2.3 HHVM compatibility

Now it's time to celebrate, but soon we'll get right back to work in order to achieve 100% HHVM compatibility for the rest of maintained Symfony branches.

Published in #Other #Symfony