簡體   English   中英

使用HipHop for PHP,PHP錯誤會發生什么

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

HipHop在C可執行文件中編譯PHP。 PHP錯誤會發生什么?

調試難嗎?

編輯:我查看了文檔但沒有找到任何內容

我做了幾個快速測試(沒有時間和我喜歡的hiphop一樣,不幸的是;-() ;這是我得到的結果:



首先,這是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


現在,讓我們嘗試訪問這三個網址; 首先,調用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選項wiki頁面判斷,您可以指定包含一些選項的配置文件。
這是我使用的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 64位上進行了這些測試 - 這是一個官方支持的系統; 安裝很簡單。

這意味着您可以嘗試這些,在虛擬機中進行安裝,例如:只要您對Linux和編譯軟件有所了解,安裝hiphop就不是一項不可能完成的任務。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM