1

I'm using phpflickr to retrieve images from Flickr. For some reason photosets_getPhotos doesn't contain the image descriptions and photos_getInfo has to be used instead. However, when I do it slows everything right down.

Here is a function I've made to retrieve an image set and display it in a prettyPhoto list.

function flickrGallery($setId,$ulClass,$prettyPhotoGroup){

   $f = new phpFlickr('KEY','SECRET',false); // API
   $user = "USERID";

   $photoset_id = $setId;
   $photos = $f->photosets_getPhotos($photoset_id);

   echo "<ul class=\"$ulClass\">\n";

   foreach ($photos['photoset']['photo'] as $photo){
      $getInfo = $f->photos_getInfo($photo['id']);
      $description = $getInfo['photo']['description'];

      $urlOrig = $f->buildPhotoURL($photo, "small");
      $urlHex = strToHex($urlOrig);
      $fullsize = $f->buildPhotoURL($photo, "large");

      echo "<li>"
          ."<a href=\"$fullsize\" rel=\"prettyPhoto[$prettyPhotoGroup]\" title=\"".$description."</pre>\">"
          ."<img src=\"/thumb/external$urlHex/120/86\" width=\"120\" height=\"80\" class=\"borderoff\" alt=\"".$photo['title']."\" />"
          ."</a>"
          ."</li>\n";
   }

   echo "</ul>\n";
}

Is there a way I can speed things up or an alternative method for getting the image descriptions?

iltdev
  • 1,789
  • 9
  • 27
  • 51
  • Is the network slow or the flickr response is slow? – ajreal Dec 14 '11 at 16:44
  • Its seems to be just the API call to getInfo causing the problem. Searching in google there seems to be a few with this issue, but I haven't found a solution unfortunately. – iltdev Dec 14 '11 at 16:49

2 Answers2

1

You can try enable caching..

  1. If you're using database caching, you'll need to supply a PEAR::DB connection string. For example: $flickr->enableCache("db", "mysql://user:password@server/database"); The third (optional) argument is expiration of the cache in seconds (defaults to 600). The fourth (optional) argument is the table where you want to store the cache. This defaults to flickr_cache and will attempt to create the table if it does not already exist.

  2. If you're using filesystem caching, you'll need to supply a folder where the web server has write access. For example: $flickr->enableCache("fs", "/var/www/phpFlickrCache"); The third (optional) argument is, the same as in the Database caching, an expiration in seconds for the cache.

source

Sendy
  • 170
  • 5
1

Unfortunately the API doesn't have any other calls to grab the description.

As an alternative, could you write more descriptive Titles for your photos and display the Title field instead of the Description field?

I would've left this as a comment but I haven't gained that privilege in Stack Overflow yet :(

Brett DeWoody
  • 59,771
  • 29
  • 135
  • 184
  • Cheers. A good workaround. It seems Flickr has you going all over the place to get the information required. I'm sure there will be a technical reason for this, but it doesn't half slow everything down! Caching and a Cron job looks like my best option. – iltdev Jan 12 '12 at 08:58