Options

phpSmug and CURL Error 7

davenelsondavenelson Registered Users Posts: 4 Beginner grinner
Today for at least a couple hours I was receiving an error on my website using phpSmug and the PHP API. When the error was present and the code was on my home page it took a very long time for the code to throw an error and kept the rest of the home page from loading until it did.

It is working now, a test page is here http://davenelson.com/scripts/portfolio.php, but I am concerned about the effects of the error killing the performance of my web site and am not putting it back on my home page until I find a fix.

On the "discovery" tab under API Keys, I did not previously have the URL for my app, did that cause the error?

I plan on using this code on multiple pages, does each page need a unique API Key so that it can have a unique URL?

One thing I plan on doing is loading the entire thing using AJAX so it will not affect the performance of the home page and the other is putting some default images in the error block so that it will at least show something when the error occurs.

But I need to know, what causes this error and how do I fix it so that I never see it again?


P.S. About the app
I am using phpSmug to anonomously retrieve the URLs and Captions for the images in a gallery and insterting them into a JavaScript that uses Fotoramajs, a jQuery slideshow library, to display the images and captions in a responsive design that works great on all devices.

Comments

  • Options
    lildudelildude Registered Users Posts: 70 Big grins
    edited May 4, 2013
    The error you got is saying that curl was unable to establish a connection with the SmugMug API endpoint. This is a network level connection so the most common culprits are network related, ie NIC, network itself, firewall, proxy or even the API endpoint. Accordingly, your API level settings are not likely to have caused this.

    As for stopping this from occurring again: you can't really do this as this is a network level issue. That said, you could probably have phpSmug timeout a little quicker so it has less of an impact. By default phpSmug uses a connect timeout of 5 seconds. This is probably a little high, but I went for the "safe rather than sorry" route.

    You can reduce the timeout to 1 second for example using:

    $f = new phpSmug( "APIKey=", "AppName=" );
    $f->req->setConfig(array( 'timeout' => 1));

    ... and then continue with the rest of your code.

    I have plans to make configuring the request settings a little easier for those who need to.

    HTH
    Colin
  • Options
    davenelsondavenelson Registered Users Posts: 4 Beginner grinner
    edited May 4, 2013
    Thank you for the reply Colin. I will definitely change the timeout.

    If I use disk based caching, can I get it to automatically pull from the cache when it times out and not clean out the cache even if it has expired if it is unable to connect to the API?
  • Options
    lildudelildude Registered Users Posts: 70 Big grins
    edited May 4, 2013
    Unfortunately, not at the moment. It's one of the things I'm working on (I've just added it as an issue on GitHub so I don't forget). That said, the only thing cached is the API responses. You'd still need to be able to access the images from SmugMug.
  • Options
    davenelsondavenelson Registered Users Posts: 4 Beginner grinner
    edited May 5, 2013
    My solution so far is to write my required data to a table when it is successfully retrieved from the API, then if the API fails for any reason the data is pulled from the database.

    Colin, thank you for all your work on phpSmug.
Sign In or Register to comment.