gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 00:02:38 24 4
gpt4 key购买 nike

HipHop在C可执行文件中编译PHP。 PHP错误会发生什么?

调试起来更难吗?

编辑:我浏览了文档,但没有找到任何东西

最佳答案

我做了几个快速测试(不幸的是,我没有时间像我想的那样玩嘻哈音乐;-();这是我得到的结果:



首先,这是test-2.php的内容,其中包含一个解析错误:

<?php

echo "what with a parse error ?

注意:字符串未完成

尝试用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

尝试使用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

即具有解析错误的文件无法编译-这是合理的。

该错误消息具有PHP错误消息中提供的一些信息-但不完全准确...

这意味着您可能想在尝试使用hiphop编译应用程序之前尝试使用PHP: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";

尝试从Apache + PHP运行该文件,您将遇到三个可能的错误:
(我已将文件复制到我的文档根目录中-这意味着路径与Apache错误不会相同)

首先,调用 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

而且,尝试 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

最后,通过 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

现在,使用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

然后,启动服务器:
$ /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

现在,让我们尝试访问这三个URL;首先,调用 http://localhost:8080/test-1.php?test=1我得到:
  • 浏览器中什么都没有
  • 我从中启动服务器的控制台中的
  • Unhandled error: Invalid operand type was used: not ArrayAccess objects.
    对于http://localhost:8080/test-1.php?test=2,我得到:
  • 在浏览器中:plop
  • 在启动浏览器的控制台中:Division by zero

  • 最后,对于 http://localhost:8080/test-1.php?test=3,我得到:
  • 在浏览器中:plop
  • 在控制台中:无

  • 在这里,错误的指示也不如PHP那样好……至少在默认选项下……



    从hiphop的 Runtime options wiki page来看,您可以指定一个包含一些选项的配置文件。
    这是我使用的 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
    }

    重新启动服务器,使用 --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

    我应该获得更多信息...让我们再次尝试三个请求。

    首先,调用 http://localhost:8080/test-1.php?test=1我得到:
  • 之前相同

    对于 http://localhost:8080/test-1.php?test=2,我得到:
  • 之前相同

    最后,对于 http://localhost:8080/test-1.php?test=3,我得到:
  • 在浏览器中:plop
  • 在控制台中:我之前从未收到过的新错误消息:f_file_put_contents/316: Permission denied

  • 我没有做更多尝试,但是使用该配置文件和 --config开关似乎是一个有趣的主意;-)



    注意:我在Ubuntu 9.10 64bits上进行了这些测试-这是官方支持的系统;安装是很容易的。

    这意味着您可以尝试在虚拟机中进行安装,例如:只要您对Linux和编译软件有所了解,安装hiphop并非不可能。

    关于php - 使用HipHop for PHP,PHP错误会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2416595/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com