How to programmatically check if running on HHVM?
Asked Answered
F

2

22

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
}
Felic answered 26/12, 2013 at 0:9 Comment(0)
O
35

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

Orten answered 26/12, 2013 at 0:13 Comment(1)
Great! Missed that post. Personally, I prefer to wrap this logic on a function or method.Felic
F
-2

Some older versions of HHVM don't have HHVM_VERSION defined. They all output "HipHop" in phpinfo().

function is_hhvm(){
  ob_start();
  phpinfo();
  $info=ob_get_contents();
  ob_end_clean();
  return ($info=='HipHop');
}
Frisk answered 19/1, 2014 at 15:37 Comment(1)
Don't do this. We'll make phpinfo be more like PHP5 at some point.Blynn

© 2022 - 2024 — McMap. All rights reserved.