How to programmatically check if running on HHVM?

marcio picture marcio · Dec 26, 2013 · Viewed 8.3k times · Source

I need to run a given package on both HHVM runtime and traditional PHP runtime. My question: is there a way to check programmatically if current environment is HHVM? Something like this:

<?php
if(running_on_hhvm()) {
    // do hhvm compatible routine
}
else {
    // do normal routine
}

Answer

SamV picture SamV · Dec 26, 2013

You can utilise the constant HHVM_VERSION specific to HHVM:

if (defined('HHVM_VERSION')) {
    // Code
}

You can put this in your own function if you want.

function is_hhvm() {
    return defined('HHVM_VERSION');
}

if (is_hhvm()) {
    // Code
}

Source: http://www.hhvm.com/blog/2393/hhvm-2-3-0-and-travis-ci