I would use cURL anyway, it gives you more control and, in particular, gives you a timeout parameter. This is very important when calling an external API to prevent your application from freezing when you delete a remote API.
Maybe so:
# Connect to the Web API using cURL. $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.url.com/api.php?123=456'); curl_setopt($ch, CURLOPT_TIMEOUT, '3'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $xmlstr = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch);
cURL will use HTTP / 1.1 by default, unless you specify something else using curl_setopt($s,CURLOPT_HTTPHEADER,$headers); where $ headers is an array.
Jonatan littke
source share