2014-12-22 22 views
1

我有這樣的代碼:HHVM DomDocument loadHTMLFile()不起作用。 BUG?

$doc = new DOMDocument(); 
$doc->validateOnParse = true; 
$doc->formatOutput = true; 
$doc->loadHTMLFile($file); 
$raw = $doc->saveHTML(); 

當我做了var_dump($raw)它會顯示string(1) " "。有些東西顯然是錯誤的。

一個var_dump($doc)輸出

object(DOMDocument)#5228 (35) { 
    ["recover"]=> 
    bool(false) 
    ["documentURI"]=> 
    NULL 
    ["strictErrorChecking"]=> 
    bool(true) 
    ["xmlStandalone"]=> 
    bool(true) 
    ["standalone"]=> 
    bool(true) 
    ["attributes"]=> 
    NULL 
    ["nodeValue"]=> 
    NULL 
    ["resolveExternals"]=> 
    bool(false) 
    ["childNodes"]=> 
    string(22) "(object value omitted)" 
    ["previousSibling"]=> 
    NULL 
    ["nodeName"]=> 
    string(9) "#document" 
    ["xmlVersion"]=> 
    string(3) "1.0" 
    ["lastChild"]=> 
    NULL 
    ["nodeType"]=> 
    int(9) 
    ["formatOutput"]=> 
    bool(true) 
    ["firstChild"]=> 
    NULL 
    ["parentNode"]=> 
    NULL 
    ["ownerDocument"]=> 
    NULL 
    ["config"]=> 
    NULL 
    ["prefix"]=> 
    string(0) "" 
    ["implementation"]=> 
    string(22) "(object value omitted)" 
    ["preserveWhiteSpace"]=> 
    bool(true) 
    ["documentElement"]=> 
    NULL 
    ["namespaceURI"]=> 
    NULL 
    ["baseURI"]=> 
    NULL 
    ["substituteEntities"]=> 
    bool(false) 
    ["textContent"]=> 
    string(0) "" 
    ["nextSibling"]=> 
    NULL 
    ["doctype"]=> 
    NULL 
    ["validateOnParse"]=> 
    bool(true) 
    ["version"]=> 
    string(3) "1.0" 
    ["actualEncoding"]=> 
    NULL 
    ["encoding"]=> 
    NULL 
    ["localName"]=> 
    NULL 
    ["xmlEncoding"]=> 
    NULL 
} 

可能是什麼問題?

#更新:

錯誤是loadHTMLFile()。它返回一個FALSE。但爲什麼?該文件的路徑是正確的。

如果我不是這樣做:

$doc->loadHTML(file_get_contents($file)); 

它工作得很好。這是HHVM的錯誤嗎?

+0

這是否不HHVM工作的事情在常規PHP做工精細環境? – halfer

+0

我不明白爲什麼它不應該。 – Michael

+0

我認爲你已經錯過了我所做的一點。如果它在普通的PHP中工作,但不在HHVM中,那麼它可能是HHVM的一個錯誤,或者是一種已知的不同行爲。另一方面,如果它在PHP中不起作用,那麼也許你做錯了什麼。長話短說:值得在普通的PHP環境中嘗試。 – halfer

回答

1

HHVM(自版本3.3開始)默認封鎖所有外部資源。這裏是一個php.ini選項,以重新啓用它們:

hhvm.libxml.ext_entity_whitelist = file 

可以提供使用逗號分隔列表中的多個流包裝:

hhvm.libxml.ext_entity_whitelist = file,http 
+0

謝謝。我需要在哪個文件中插入此值? – Michael

+0

這是HHVM的'php.ini'文件所在的地方。如果你使用的是預編譯的ubuntu/debian軟件包,我相信這是在'/ etc/hhvm/php.ini'中。但值得注意的是,出於安全原因,這是關閉的,您應仔細調查並評估是否要重新開啓。 (我不是100%確定的細節,但這個問題類似於最近的一些Rails漏洞,你可以利用它來誘騙它加載YAML文件,並且通過某種模式加載某些東西,如果你不是,那麼就相當於任意代碼exec小心點。) –

相關問題