Bitly API error handler

Closed - This job posting has been filled and work has been completed.

Job Description

I get a shortlink for Bit.ly using this code:

<?php
function make_bitly_url($url) {
$bitly = 'http://api.bit.ly/shorten?version=2.0.1&amp;longUrl='.urlencode($url).'&amp;login=seatbytext&amp;apiKey=R_5529016dcb84dfabc68706ae8d523a72&amp;format=json';
$response = file_get_contents($bitly);
$json = @json_decode($response,true);
return $json['results'][$url]['shortUrl'];
}
?>

It works great. Lately their server has been having issues and it is hanging up my scripts and causing my app to crash. I need a way to set a time limit on the call.

Essentially:

1. Try to get short link (Done Above)
2. If, after 2-3 seconds, bitly hasnt responded or sent back an error, or sent back nothing...handle it
3. If bit.ly sent back response....execute rest of page (Done)

I need step 2 taken care of and I need php to help me determine it so I can handle that

Something like this:

<?php
if (bitly gave error) {

DO SOME SCRIPT;
}
else {

CONTINUE LIKE I HAVE SET-UP NOW;
}

Should be a quick script for a bit.ly api and php expert.

Need it TODAY!

Dave