Problems repeatedly grabbing Smugmug data
Lint
Registered Users Posts: 27 Big grins
I have a php page - using phpmug wrapper - that pulls all albums, categories and sub-categories from my smugmug account and displays the hierarchy it gets. I'm using oauth but I had much the same problem with email/password login. The first couple of times I refresh the page I get the data fine but then I get what appears to be a php timeout after 10-15 seconds - blank page, no errors.
If I force a limit on the number of sub-categories (currently 60, mostly empty) then the page comes back but just what limit works depends very much on how fast I refresh. 10 usually works, 30 often but not always fails.
I'm a bit of an oauth newbie so I'm probably missing something very obvious. Or is there a limit on how many times or how fast I can make API calls to Smugmug? Or is it a session thing maybe?
I'm basically doing this
(siteground php timeout is set at 10 seconds, I can't change it).
If I force a limit on the number of sub-categories (currently 60, mostly empty) then the page comes back but just what limit works depends very much on how fast I refresh. 10 usually works, 30 often but not always fails.
I'm a bit of an oauth newbie so I'm probably missing something very obvious. Or is there a limit on how many times or how fast I can make API calls to Smugmug? Or is it a session thing maybe?
I'm basically doing this
$options = get_option( 'smuglymugly'); $f = new phpSmug("APIKey=" . $options['apikey'], "AppName=" . $options['apistring'], "OAuthSecret=" . $options['secret'], "APIVer=1.2.0" ); $token = $options['token']; $f->setToken("id={$token['Token']['id']}", "Secret={$token['Token']['Secret']}");before grabbing everything I need.
(siteground php timeout is set at 10 seconds, I can't change it).
0
Comments
But 10 seconds sounds like a long time. I have a function that gets all the urls for the over 1000 albums in a category and write it to a file and it's done almost instantaneously.
Want faster uploading? Vote for FTP!
That was my thinking. The real pain, of course, is that nothing's coming back and I'm not getting debug statements. I'm going to have to do some file logging, I think.
thanks for the input.
www.flickr.com/photos/kimaldis/
This is my code. Basically, I'm grabbing albums, then categories then looping through each category to get subcategories under the category. I have around 60 categories. If I limit it to 10-15 I get many fewer blank pages in a sequence but still occasionally:
www.flickr.com/photos/kimaldis/
You can keep breaking it down until it's basically just getting one album at a time if need be. And you'll probably have to use some sort of marker in the file since the php script needs to finish in under 10 seconds. This way, it can quickly read the file and pick up where it left off.
Want faster uploading? Vote for FTP!
That's an awfully long time to wait for a page load. I'd have to go and make a cup of tea. Or 3 ;-)
A better way would be to load all the albums, all the categories, all the subs and build the tree from that. Assuming it's the number of rapidly sequential calls that's causing the problem, of course.
That's really what I was trying to find out, I guess; whether making a bunch of API calls like that in rapid succession is a no-no. If it is, I may have to have a bit of a re-think.
www.flickr.com/photos/kimaldis/
Want faster uploading? Vote for FTP!
But I think there's a much quicker and more efficient way to do what you want. The category and sub-category information is already there in $albums once you get that. You can just parse the information from it using standard php operations and display the results. No need to grab it again from the API.
Want faster uploading? Vote for FTP!
www.flickr.com/photos/kimaldis/
There's a lot of different methods to implement too. You can use php array_count_values to just count the categories/sub-categories. The resulting array will give you all of your categories/sub-categories. There may be a way to use array_unique, or compact, or count, or uasort. And these are just from some simple looking around on php.net. A google search for the exact thing you want--output all unique values in an array--will probably lead you right to the code.
Want faster uploading? Vote for FTP!
www.flickr.com/photos/kimaldis/
This will ultimately, for anyone interested, be a Wordpress plugin for Smugmug. It's currently driving images and slide shows on the first couple of posts on my website - see sig - and I'll be making it publicly available once I'm comfortable that it's not going to explode the Internet.
Thanks to everyone who input.
K.
www.flickr.com/photos/kimaldis/
I didn't know about getAll for the subcats. Good find.
So I'm curious, what the functionality of your plugin will do exactly? I only know about retrieving albums, categories, and subcats from the development of a little random picture module for my main website which allowed someone to click on the image and be taken to that image in its source gallery. I checked out your wordpress site, but didn't really notice where the plugin was operating. I guess that's the sign of a good design.
Want faster uploading? Vote for FTP!
I'll also be adding a couple of widgets with a gallery tree and something that displays a number of random thumbnails and behind the scenes in the admin pages I'll be adding a treeview of the gallery that lets you grab off the shortcodes rather than digging around in albums. I'd also quite like a d&d into the tree allowing you to organise your smugmug gallery more easily.
I'm still thinking about the whole sell, print and email thing but I'd like to figure a way of making that easy from the site too.
I'm also open to suggestions but what I'm really after is a way to blog and show off work on my own site but only have to maintain one archive of images.
www.flickr.com/photos/kimaldis/
Hey I just found something that might be even better for building your tree: smugmug.users.getTree "Retrieve a hierarchical album tree for a user."
Want faster uploading? Vote for FTP!
The problem that I may run into is the same one Lint mentioned here in the thread. I was going to retrieve an album's image list via smugmug.images.get and then use a foreach on each of the images in the resulting array, have it pass each of the image id and keys to smugmug.images.collect to collect each image. But the problem is, a loop like this would execute in milliseconds and hammer the API server with possibly hundreds of request in a second. Will it be able to handle it or will I run into the same problem Lint did?
If I will run into problems, what's the spacing need to be like? 5 seconds, 1 second, 1/2 second?
Want faster uploading? Vote for FTP!
I should say though, that I'm still not sure if this is a problem caused by my not storing something in the session. Although I'm only getting a new phpSmug object the once on a page, during the testing process I'm calling it multiple times in the session. I'm wondering if this might be wrong.
If nobody minds, I'm going to move this over to support to see if I can't get some thoughts from the smugmug end.
www.flickr.com/photos/kimaldis/
If you could have support chime in on the discussion here, that would help everyone.
Want faster uploading? Vote for FTP!
If you aren't using all the info that is returned from that response, I recommend that you build your own custom response using the Extras parameter by including any parameters that you want kinda like this...
Cheers,
David
SmugMug API Developer
My Photos
Want faster uploading? Vote for FTP!