检测程序是通过 HipHop 还是常规 CLI/mod_php 运行
我想知道是否有人找到了一种方法来检测 PHP 脚本/程序是否通过 Facebook 的 HipHop 或“常规”环境(CLI、mod_php、CGI)运行。
目前我使用的解决方法是寻找未实现的功能(例如 PHP 5.3 函数)并检查该功能的可用性。当然,这是一个相当狡猾的黑客(并且不可移植),因为随着 HipHop 的成熟,将会实现越来越多的功能。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 HipHop 下运行时,
$_ENV['HPHP']
设置为 1。感谢 nicolasff 提供的解决方案
参考:https://github.com/facebook /hiphop-php/issues/382#issuecomment-1754648
$_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
我认为这种方法根本不起作用——因为 HipHop 静态编译项目中的所有代码,所以你不能包含 HipHop 无法理解的任何代码路径或函数调用,即使它们在运行时被跳过。基本上,为了让您的项目在 HipHop 下运行,您必须在假设正在使用它的情况下编写大部分(如果不是全部)代码。
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.