dqn48247 2016-07-31 11:32
浏览 60
已采纳

libxml_set_external_entity_loader在httpd中不起作用

I can't get the function libxml_set_external_entity_loader work within apache.

This is my test.php (took from http://php.net/manual/en/function.libxml-set-external-entity-loader.php):

<?php
$xml = <<<XML
<!DOCTYPE foo PUBLIC "-//FOO/BAR" "http://example.com/foobar">
<foo>bar</foo>
XML;

$dtd = <<<DTD
<!ELEMENT foo (#PCDATA)>
DTD;

libxml_disable_entity_loader(false);

libxml_set_external_entity_loader(
    function ($public, $system, $context) use($dtd) {
        var_dump($public);
        var_dump($system);
        var_dump($context);
        $f = fopen("php://temp", "r+");
        fwrite($f, $dtd);
        rewind($f);
        return $f;
    }
);

$dd = new DOMDocument;
$r  = $dd->loadXML($xml);

var_dump($dd->validate());

The result always failed in browser when access this test.php file:

Warning: DOMDocument::validate(http://example.com/foobar): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in /www/test.php on line 28

Warning: DOMDocument::validate(): I/O warning : failed to load external entity "http://example.com/foobar" in /www/test.php on line 28

Warning: DOMDocument::validate(): Could not load the external subset "http://example.com/foobar" in /www/test.php on line 28
bool(false) 

While it works with php in terminal:

$ php test.php


string(10) "-//FOO/BAR"
string(25) "http://example.com/foobar"
array(4) {
  ["directory"]=>
  NULL
  ["intSubName"]=>
  NULL
  ["extSubURI"]=>
  NULL
  ["extSubSystem"]=>
  NULL
}
bool(true)

Both httpd and php were built from source on Mac OS. phpinfo() result is uploaded here https://dl.dropboxusercontent.com/u/11335326/phpinfo().html

Can anyone point out which is the problem? Thanks!

  • 写回答

1条回答 默认 最新

  • doucan4873 2016-08-08 08:48
    关注

    Rebuid httpd with --enable-mpms-shared=all and then add LoadModule mpm_prefork_module modules/mod_mpm_prefork.so into httpd.conf solved this.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度