简体   繁体   English

如何使用PHP加速XML DTD验证?

[英]How to speed up the XML DTD validation with PHP?

I am walidating my XML with a DTD file I have locally. 我用我在本地的DTD文件来验证我的XML。

For that, I am doing: 为此,我正在做:

$xml                = $dmsMerrin.'/xml/'.$id.'/conversion.xml';
$dtd                = $dmsMerrin.'/style_files/journalpublishing.dtd';

$dom = new DOMDocument();
@$dom->load($xml);

libxml_use_internal_errors(true);

if (@$dom->validate()) {
    $htmlDTDError .= "<h2>No Errors Found - The tested file is Valid !</h2>";
} 
else {
    $errors = libxml_get_errors();
    $htmlDTDError .= '<h2>Errors Found ('.count($errors).')</h2><ol>';

    foreach ($errors as $error) {
        $htmlDTDError .= '<li>'.$error->message.' on line '.$error->line. '</li>';
    }

    $htmlDTDError .= '</ol>';
    libxml_clear_errors();
}

libxml_use_internal_errors(false);

And this takes about 30sec for an XML with 1600 lines. 对于1600行的XML,这需要大约30秒。

Is this a usual time? 这是平时吗? Should be much faster in my opinion? 我认为应该快得多吗?

As you can see, the DTD I am using is locally on the server. 如您所见,我使用的DTD是本地服务器上的。

Any idea? 任何的想法? Thank you. 谢谢。

EDIT: By debuging and checking the execution time, I noticed that it takes the same time if my xml has 1600 lines or 150 lines, so the problem is not the xml size. 编辑:通过调试和检查执行时间,我注意到如果我的xml有1600行或150行,它需要相同的时间,所以问题不是xml大小。

And this takes about 30sec for an XML with 1600 lines. 对于1600行的XML,这需要大约30秒。

That's an unusually long time, and it's likely due to misconfiguration. 这是一个异常漫长的时间,可能是由于配置错误造成的。

By debuging and checking the execution time, I noticed that it takes the same time if my xml has 1600 lines or 150 lines, so the problem is not the xml size. 通过调试和检查执行时间,我注意到如果我的xml有1600行或150行,则需要相同的时间,因此问题不在于xml大小。

For a tool that may provide more diagnostics here, try xmllint --valid . 对于可在此处提供更多诊断的工具,请尝试xmllint --valid It will show, for example, errors for any DTDs that could not be retrieved. 例如,它将显示无法检索的任何DTD的错误。

It's very likely that the extra time is due to fetching resources, such as the DTD, needed to perform validation. 额外的时间很可能是由于获取执行验证所需的资源(例如DTD)。

For one of your files, confirm that the URL of the DTD can be retrieved quickly by testing with a tool like curl from the same server. 对于您的某个文件,请确认可以通过使用来自同一服务器的curl工具进行快速检索,从而快速检索DTD的URL。 Is it a complex DTD? 它是一个复杂的DTD吗? Does it bring in other files? 它带来了其他文件吗? Especially, make sure that it never refers to resources that would have to be fetched from the web, or with hostnames where DNS resolves slowly. 特别是,请确保它永远不会引用必须从Web获取的资源,或者使用DNS缓慢解析的主机名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM