When calling an external API with simplexml_load_file a server timeout or similar will generate warnings. Using file_exists on e.g. http://www.api.com?query=xyz does not work. Is there any built in function or appropriate solution for a simple check before performing the simplexml_load_file?
When calling an external API with simplexml_load_file a server timeout or similar will generate
Share
You can use file_get_contents, which you can check if it was successful based on its return values (false on failure, data on success). You can also use
@like so to suppress any warnings:Finally, use simplexml_load_string instead of simplexml_load_file using the data that
file_get_contentsreturned to create your SimpleXMLElement object.