$url = “http://www.xyz.com/restservices/assignment/section/1/userid/2864182”;
$assignlist = @file_get_contents($url); ---- this shows a 504 Gateway Timeout error
If I directly access the url in browser then it shows “NetworkError: 503 Service Unavailable…d server is at capacity” — before calling file_get_contents function is it possible to check whether the external service is available at all or not.
$host = '193.33.186.70';
$port = 80;
$waitTimeoutInSeconds = 1;
if($fp = fsockopen($host,$port,$errCode,$errStr,$waitTimeoutInSeconds)){
// It worked
} else {
// It didn't work
}
fclose($fp);
source: http://stackoverflow.com/questions/9841635/how-to-ping-a-server-port-with-php
Edit : file_get_contents will not work with URIs without allow_url_fopen set to ON.
You should get the content with cURL and this way you can also check if the resource is available (cURL works almost like fsockopen)
You might consider using the get_headers() function.
http://php.net/manual/en/function.get-headers.php
In the comments of that page, you will notice an example to get the response code.
<?php
function get_http_response_code($theURL) {
$headers = get_headers($theURL);
return substr($headers[0], 9, 3);
}
?>
You could then use that like…
$url = "http://www.xyz.com/restservices/assignment/section/1/userid/2864182";
$assignlist = '';
if(get_http_response_code($url) == '200') {
$assignlist = @file_get_contents($url);
}
The same could also be done via cURL like vectorialpx mentions.