Flickr API sometimes returns false, but usually works, why?

I'm constructing this URL with PHP and getting the result from Flickr with CURL.

http://api.flickr.com/services/rest?api_key=APIKEY&format=php_serial&method=flickr.photosets.getPhotos&photoset_id=72157594403088940&per_page=200&extras=description,url_l,url_c,url_z,url_m,url_n,url_s,url_t

There is a real API key there of course. Anyway it sometimes returns bool(false), sometimes the proper list of images. Usually it's like first time check on a given day returns false, then after a refresh it gets the list properly. My CURL function I use to get the result:

function file_get_contents_curl($url, $curlopt = array()){      
        if(in_array('curl', get_loaded_extensions())){
            $ch = curl_init();
            $default_curlopt = array(
            CURLOPT_TIMEOUT => 2,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_FOLLOWLOCATION => false,
            CURLOPT_USERAGENT => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 AlexaToolbar/alxf-1.54 Firefox/3.6.13 GTB7.1"
            );
            $curlopt = array(CURLOPT_URL => $url) + $curlopt + $default_curlopt;
            curl_setopt_array($ch, $curlopt);
            $response = curl_exec($ch);
            if($response === false)
            trigger_error(curl_error($ch));
            curl_close($ch);
            return $response;
        }else{
            return file_get_contents($url);
        }
    }

What is this and why does it happen? Maybe it has something to do with my CURL function (my best bet)?

Upvotes: 0

Views: 339

Answers (1)

web-nomad
web-nomad

Reputation: 6003

You have set the CURLOPT_TIMEOUT to 2 seconds. Can you verify if the code times out before the execution completes. If so, try increasing it a bit and see if it works.

Just a guess.

Upvotes: 1

Related Questions