如果与远程服务器没有连接,如何放弃file_get_contents()请求?

My shipping company has an "API" which instructs me to use file_get_contents() in order to receive a shipping quote.

$zipcode=1234;
$volume=2;

$shipping_quote=file_get_contents(http://www.shipping.com?z=$zipcode&v=$volume);

Occasionally, their server will be down and I will receive no response. Is there someway to check if file_get_contents has made a connection? I am getting "failed to open stream errors". Instead of these, I would like to be able to present my users with a meaningful response "Server busy, Try again".

Try like this

 //initialize curl
$URL = "http://www.shipping.com";
$curlInit = curl_init($URL);
curl_setopt($curlInit,CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($curlInit,CURLOPT_HEADER,true);
curl_setopt($curlInit,CURLOPT_NOBODY,true);
curl_setopt($curlInit,CURLOPT_RETURNTRANSFER,true);
//check for response
$response = curl_exec($curlInit);
curl_close($curlInit);

if ($response) 
{
    $shipping_quote=file_get_contents("http://www.shipping.com?z=$zipcode&v=$volume");
}else
{
    $shipping_quote="";
}