Home » Php » simplexml works on one host but not another. PHP xml directives are correct. Why?

simplexml works on one host but not another. PHP xml directives are correct. Why?

Posted by: admin February 25, 2020 Leave a comment

Questions:

The following code works on Host1

$url = "https://<redacted>";
$xml=simplexml_load_file($url);
$result = $xml->result;

On Host2 the following warning and notice are returned when using the exact same code:

Warning: simplexml_load_file(https:)failed to open stream: Connection timed out in /usr/www/users/…etc.
Notice: Trying to get property ‘result’ of non-object in /usr/www/users…etc.

If I copy the url presented in the error message and paste it into a browser, it works correctly and the xml tree is returned.

On Host2 all xml directives are enabled and allow_url_fopen is enabled.

I do not have access to the server logs so cannot examine them but no errors are logged in the site error log.

I attempted using curl with the following code:

$cl = curl_init();
curl_setopt($cl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cl, CURLOPT_URL, $url);
$contents = curl_exec($cl);
curl_close($cl);

if ($contents) return $contents;
else return FALSE;
print_r($contents);

but I then get a “service unavailable” error from the host server after the timeout period expires.

How to&Answers:

Seems likes you host is blocked by that website. You call many times with that url?

Check this one :

https://stackoverflow.com/a/34505846/11426374