我使用PHP的内置功能将从外部源接收的XML字符串/数据集转换为HTML。
虽然这在我的开发服务器上运行良好,但在(另一家公司的)实时服务器上不起作用。
我找不到问题,所以他们从错误日志中给我发了一些行:
〔2016年4月12日星期二15:29:33〕〔error〕〔client xx.xxx.xxxx.xx〕PHP警告:DOMDocument::load(http://mysite/wp-content/themes/mytheme/xsl/content.xsl)[domdocument.load]:无法打开流:第492行上的/var/www/html/mysite/wp-content/themes/mytheme/functions.php中的连接超时
〔2016年4月12日星期二15:29:33〕〔error〕〔client xx.xxx.xxxx.xx〕PHP警告:DOMDocument::load()〔DOMDocument.load〕:I/O警告:无法加载外部实体"http://mysite/wp-content/themes/mytheme/xsl/content.xsl"在/var/www/html/mysite/wp-content/themes/mytheme/functions.php的492 行
〔2016年4月12日星期二15:29:33〕〔error〕〔client xx.xx.xxx.xx〕PHP警告:XSLTProcessor::importStylesheet()〔XSLTProcessor.importStylesheet〕:第498行/var/www/html/mysite/wp-content/themes/mytheme/functions.PHP中的编译错误
〔2016年4月12日星期二15:29:33〕〔error〕〔client xx.xx.xxx.xx〕PHP警告:XSLTProcessor::importStylesheet
这看起来像是找不到xslt文件,但这对我来说没有什么意义,因为它被放在本地文件夹中,所以没有理由删除"连接超时"?!?
这是创建错误的函数,对我来说看起来很好
// Execute XSLT on given string
function xslt_transformation($the_xml_string)
{
$xml = new DOMDocument;
$xml->loadXML($the_xml_string);
$xsl = new DOMDocument;
$xsl->load('wp-content/themes/mytheme/xsl/content.xsl');
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl);
return $proc->transformToXML($xml);
}
我能找到什么线索或想法吗
更新1:同时我修改了代码,以确保它为XSL查找本地文件。这可能会将http调用保存到一个子目录之外的文件中。至少我希望如此,我不知道PHP是否足够聪明,以前可以检查一下
更新2:我用本地加载的XSLT进行了一些测试,整个系统现在似乎运行得更快了,至少这次没有出现可疑的超时。我将使用较大的XML文档进行更多的测试
您似乎在使用Wordpress。
你试过@Amin.T的建议了吗?
或
你能验证文件夹/文件的权限吗?请参阅此URL:https://codex.wordpress.org/Changing_File_Permissions