简体   繁体   English

使用HipHop for PHP,PHP错误会发生什么

[英]With HipHop for PHP, what happens with PHP errors

HipHop compiles PHP in a C executable. HipHop在C可执行文件中编译PHP。 What happens with PHP errors ? PHP错误会发生什么?

Is that harder to debug ? 调试难吗?

edit : I looked through the documentation but didn't find anything 编辑:我查看了文档但没有找到任何内容

I did a couple of quick tests (haven't have the time to play with hiphop as much as I'd like, unfortunately ;-( ) ; here are the results I got : 我做了几个快速测试(没有时间和我喜欢的hiphop一样,不幸的是;-() ;这是我得到的结果:



First of all, here's the content of test-2.php , which contains a parse error : 首先,这是test-2.php的内容,其中包含一个解析错误:

<?php

echo "what with a parse error ?

Note : the string is not finished 注意:字符串未完成


Trying to run that with PHP, I get : 试着用PHP运行它,我得到:

$ php test-2.php 
PHP Parse error:  syntax error, unexpected $end, expecting T_VARIABLE or T_DOLLAR_OPEN_CURLY_BRACES or T_CURLY_OPEN in /home/squale/temp/hiphop-php/tests/test-2.php on line 5

Parse error: syntax error, unexpected $end, expecting T_VARIABLE or T_DOLLAR_OPEN_CURLY_BRACES or T_CURLY_OPEN in /home/squale/temp/hiphop-php/tests/test-2.php on line 5


Trying to compile that with hiphop, I get : 试着用hiphop编译,我得到:

$ /home/squale/temp/hiphop-php/hiphop-php/src/hphp/hphp test-2.php --keep-tempdir=1 --log=3
running hphp...
creating temporary directory /tmp/hphp_JdsWcU ...
parsing inputs...
parsing ./test-2.php...
parsing inputs took 0'00" (0 ms) wall time
running hphp took 0'00" (154 ms) wall time
Exception: Unable to parse file: ./test-2.php
 (Line: 5, Char: 0): syntax error, unexpected $end

ie the file with the parse error doesn't compile -- which stands to reason. 即具有解析错误的文件无法编译 - 这是有道理的。

The error message has some informations that were present in the PHP's error message -- but not exactly as precise... 错误消息有一些信息存在于PHP的错误消息中 - 但不完全一样精确...

Which means you might want to try with PHP before trying to compile your application with hiphop : the error message given by PHP was more descriptive. 这意味着您可能希望在尝试使用hiphop编译应用程序之前尝试使用PHP:PHP提供的错误消息更具描述性。



Now, let's try with some runtime errors/warnings ; 现在,让我们尝试一些运行时错误/警告; here's the content of test-1.php : 这是test-1.php的内容:

<?php                                                                                                                                                                                                                                                                          

error_reporting(E_ALL);                                                                                                                                                                                                                                                        
ini_set('display_errors', 'On');                                                                                                                                                                                                                                               

if ($_GET['test'] == '1') {                                                                                                                                                                                                                                                    
        $data = (object)array(10);                                                                                                                                                                                                                                             
        echo $data[0];                                                                                                                                                                                                                                                         
} else if ($_GET['test'] == '2') {                                                                                                                                                                                                                                             
        echo 10/0;                                                                                                                                                                                                                                                             
} else if ($_GET['test'] == '3') {                                                                                                                                                                                                                                             
        file_put_contents('/bin/non-allowed', 'hello !');                                                                                                                                                                                                                      
}

echo "plop\n";

Trying to run that file from Apache+PHP, you'd get three possible errors : 试图从Apache + PHP运行该文件,你会得到三个错误:
(I copied the file to my document root -- which means the paths will not be the same for the errors with Apache) (我将文件复制到我的文档根目录 - 这意味着Apache的错误路径不一样)

First of all, calling http://localhost/temp/test-1.php?test=1 I get : 首先,调用http://localhost/temp/test-1.php?test=1我得到:

Fatal error: Cannot use object of type stdClass as array in /home/squale/developpement/tests/temp/test-1.php on line 8

And, trying http://localhost/temp/test-1.php?test=2 I get : 并且,尝试http://localhost/temp/test-1.php?test=2我得到:

Warning: Division by zero in /home/squale/developpement/tests/temp/test-1.php on line 10
plop 

And, finally, with http://localhost/temp/test-1.php?test=3 , I get : 最后,使用http://localhost/temp/test-1.php?test=3 ,我得到:

Warning: file_put_contents(/bin/non-allowed) [function.file-put-contents]: failed to open stream: Permission denied in /home/squale/developpement/tests/temp/test-1.php on line 12
plop


Now, compiling that test-1.php file with hiphop and running it in web-server mode, I get this during the compilation phase, which means it is OK : 现在,使用hiphop编译test-1.php文件并在Web服务器模式下运行它,我在编译阶段得到了这个,这意味着它没问题:

$ /home/squale/temp/hiphop-php/hiphop-php/src/hphp/hphp test-1.php --keep-tempdir=1 --log=3
running hphp...
creating temporary directory /tmp/hphp_xXZ8US ...
parsing inputs...
parsing ./test-1.php...
parsing inputs took 0'00" (1 ms) wall time
pre-optimizing...
pre-optimizing took 0'00" (0 ms) wall time
inferring types...
inferring types took 0'00" (0 ms) wall time
post-optimizing...
post-optimizing took 0'00" (0 ms) wall time
creating CPP files...
creating CPP files took 0'00" (32 ms) wall time
compiling and linking CPP files...

compiling and linking CPP files took 0'39" (39807 ms) wall time
running executable /tmp/hphp_xXZ8US/program --file test-1.php...
plop
all files saved in /tmp/hphp_xXZ8US ...
running hphp took 0'40" (40054 ms) wall time

And, then, launching the server : 然后,启动服务器:

$ /tmp/hphp_xXZ8US/program -m server -p 8080
Could not mlockall
loading static content...
loading static content took 0'00" (0 ms) wall time
page server started
admin server started
all servers started


Now, let's try accessing those three URLs ; 现在,让我们尝试访问这三个网址; first, calling http://localhost:8080/test-1.php?test=1 I get : 首先,调用http://localhost:8080/test-1.php?test=1我得到:

  • Nothing in the browser 浏览器中没有任何内容
  • Unhandled error: Invalid operand type was used: not ArrayAccess objects. in the console from which I started the server 在我启动服务器的控制台中

For http://localhost:8080/test-1.php?test=2 , I get : 对于http://localhost:8080/test-1.php?test=2 ,我得到:

  • In the browser : plop 在浏览器中: plop
  • In the console from which I started the browser : Division by zero 在我启动浏览器的控制台中: Division by zero

And, finally, for http://localhost:8080/test-1.php?test=3 , I get : 最后,对于http://localhost:8080/test-1.php?test=3 ,我得到:

  • In the browser : plop 在浏览器中: plop
  • In the console : nothing 在控制台: 什么都没有

Here, too, indications of errors are not quite as good as with PHP... at least with default options... 在这里,错误的迹象也不如PHP那么好...至少在默认选项中......



Judging from hiphop's Runtime options wiki page , you can specify a config file that contains some options. 从hiphop的Runtime选项wiki页面判断,您可以指定包含一些选项的配置文件。
Here's the content of the config.txt I used : 这是我使用的config.txt的内容:

Log {
    Level = Verbose
    NoSilencer = true
    AlwaysLogUnhandledExceptions = true
    RuntimeErrorReportingLevel = 6143
    Header = false
    InjectedStackTrace = true
    NativeStackTrace = true
    MaxMessagesPerRequest = -1
}

ErrorHandling {
    CallUserHandlerOnFatals = true
    NoInfiniteLoopDetection = false
    NoInfiniteRecursionDetection = false
    MaxStackDepth = 1000
    ThrowBadTypeExceptions = true
    ThrowNotices = true
    NoticeFrequency = 1    # 1 out of these many notices to log
    WarningFrequency = 1   # 1 out of these many warnings to log
    AssertActive = false
    AssertWarning = false
  }


Re-starting the server, using the --config switch to point to that file : 重新启动服务器,使用--config开关指向该文件:

$ /tmp/hphp_xXZ8US/program -m server -p 8080 --config=config.txt
Could not mlockall
loading static content...
loading static content took 0'00" (0 ms) wall time
page server started
admin server started
all servers started

I should get more informations... let's try our three requests again. 我应该获得更多信息......让我们再次尝试我们的三个请求。


First, calling http://localhost:8080/test-1.php?test=1 I get : 首先,调用http://localhost:8080/test-1.php?test=1我得到:

  • Same as before 和之前一样

For http://localhost:8080/test-1.php?test=2 , I get : 对于http://localhost:8080/test-1.php?test=2 ,我得到:

  • Same as before 和之前一样

And, finally, for http://localhost:8080/test-1.php?test=3 , I get : 最后,对于http://localhost:8080/test-1.php?test=3 ,我得到:

  • In the browser : plop 在浏览器中: plop
  • In the console : a new error message that I didn't get before : f_file_put_contents/316: Permission denied 在控制台中:我之前没有收到的新错误消息: f_file_put_contents/316: Permission denied


I didn't try much more, but playing with that config file and the --config switch looks like an interesting idea ;-) 我没有尝试更多,但玩配置文件和--config开关看起来像一个有趣的想法;-)



Note : I did those tests on Ubuntu 9.10 64bits -- which is an officially supported system ; 注意:我在Ubuntu 9.10 64位上进行了这些测试 - 这是一个官方支持的系统; installation was quite easy. 安装很简单。

Which means you could try those, doing an install in a Virtual Machine, for example : as long as you know a bit about Linux and compiling software, installing hiphop is not an impossible task. 这意味着您可以尝试这些,在虚拟机中进行安装,例如:只要您对Linux和编译软件有所了解,安装hiphop就不是一项不可能完成的任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM