Bitly API error handler

Closed - This job posting has been filled and work has been completed.
Web, Mobile & Software Dev Web Development Posted 2 years ago

Fixed Price

Delivery by January 13, 2013

$10.00

Budget

Details

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


About the Client

(4.95) 84 reviews

United States
Tampa 05:13 PM

117 Jobs Posted
82% Hire Rate, 1 Open Job

Over $10,000 Total Spent
98 Hires, 3 Active

$13.21/hr Avg Hourly Rate Paid
688 Hours

Member Since Jun 15, 2009