I am using PHP´s built-in functionality to transform a XML-string/dataset I receive from an external source to convert it into HTML.
While this worked fine on my development server, it doesn´t work on the live server (from another company).
I couldn´t find the problem, so they sent me some lines from the error logs:
[Tue Apr 12 15:29:33 2016] [error] [client xx.xxx.xxx.xx] PHP Warning: DOMDocument::load(http://mysite/wp-content/themes/mytheme/xsl/content.xsl) [domdocument.load]: failed to open stream: Connection timed out in /var/www/html/mysite/wp-content/themes/mytheme/functions.php on line 492
[Tue Apr 12 15:29:33 2016] [error] [client xx.xxx.xxx.xx] PHP Warning: DOMDocument::load() [domdocument.load]: I/O warning : failed to load external entity “http://mysite/wp-content/themes/mytheme/xsl/content.xsl” in /var/www/html/mysite/wp-content/themes/mytheme/functions.php on line 492
[Tue Apr 12 15:29:33 2016] [error] [client xx.xxx.xxx.xx] PHP Warning: XSLTProcessor::importStylesheet() [xsltprocessor.importstylesheet]: compilation error in /var/www/html/mysite/wp-content/themes/mytheme/functions.php on line 498
[Tue Apr 12 15:29:33 2016] [error] [client xx.xxx.xxx.xx] PHP Warning: XSLTProcessor::importStylesheet() [xsltprocessor.importstylesheet]: xsltParseStylesheetProcess : empty stylesheet in /var/www/html/mysite/wp-content/themes/mytheme/functions.php on line 498
This looks like the xslt file could not be found but that makes little sense to me, as it´s placed in a local folder, so no reason to drop a “connection timed out”?!?
This is the function which creates the errors, looks pretty fine to me.
// 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);
}
Any hints or ideas what I could look for?
Update 1: Meanwhile I altered my code, to make sure it looks for a local file for the XSL. This might save a http-call to a file that lies just a subdirectory away. At least I hope so, I don´t know if PHP is smart enough to check that before.
Update 2: I did some testing with the locally loaded XSLT and the whole system seems to run much faster now, at least I got no dubious timeouts this time. I´ll make some more tests with larger XML documents.
Seems you are using WordPress.
Did you tried @Amin.T suggestion?
OR
Can you verify the permission for the folder/file?
Refer this URL : https://codex.wordpress.org/Changing_File_Permissions