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.

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

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀