3

I was wondering if anyone has found a way to detect whether a PHP script/program is run through Facebook's HipHop or the "regular" environment (CLI, mod_php, CGI).

Currently the workaround I am using is looking for an unimplemented feature (for instance PHP 5.3 functions) and checking for the availability of said feature. Of course, this is rather a dodgy hack (and not portable) since as HipHop matures, more and more features will be implemented.

The Mighty Rubber Duck
  • 4,388
  • 5
  • 28
  • 27
  • Just curious, for what should it be good for to know? And what does [`php_sapi_name`](http://php.net/manual/en/function.php-sapi-name.php) say? – hakre Aug 07 '11 at 23:52
  • I just tried and `php_sapi_name` returns "cli" if calling the binary from the command line. I want to have an environment detection because I want to have a different configuration loaded when running under HipHop. – The Mighty Rubber Duck Aug 08 '11 at 00:02

2 Answers2

3

$_ENV['HPHP'] is set to 1 when running under HipHop.

Thanks to nicolasff for the solution

Ref: https://github.com/facebook/hiphop-php/issues/382#issuecomment-1754648

The Mighty Rubber Duck
  • 4,388
  • 5
  • 28
  • 27
0

I don't think this approach will work at all -- as HipHop statically compiles all code in your project, you can't include any code paths or function calls which HipHop can't understand, even if they're skipped at runtime. Basically, to make your project run at all under HipHop, you will have to write most, if not all, of your code with the assumption that it's being used.

  • Well, you can perfectly run `function_exists` to see if a function is defined at all. And it should not crash if it doesn't exist. The compilation process maybe possibly automatically resolve it to a boolean value and simplify the whole expression but it does work. It is just inelegant. – The Mighty Rubber Duck Aug 09 '11 at 06:13
  • You can call `function_exists()` all you want, but there's no way to call a function afterwards -- the indirect call syntax `$x()` is off-limits in HipHop, and an explicit call to a function which HipHop doesn't implement will cause compilation to fail, even if it's behind a `function_exists()` call. –  Aug 09 '11 at 14:54