Monday, March 14, 2011

Zazzle Widget bugs

So, I'm still working through the Zazzle Widget code.  I've already fixed a bug in the get function in lastRSS.php.  Now I am working through the Parse function.  I actually think I like the Zazzle Store Gallery better, so I'm hoping it has the same problem.

I traced it down to a call to a routine called curl_init.  Again, my echo's worked before but not after.  Unfortunately, my custom error handler didn't even work here, so I couldn't get any error text out at all.  The RSS URL is passed to it, so my first thought was that even though I verified that the URL was correct, perhaps there is something wrong with it that firefox doesn't care about.  curl_init is a PHP command, so it showed up in the online PHP Manual at  This told me that the URL didn't have to be passed, so I tried calling it without it.  Still no luck.  I even tried creating a test page that did nothing except call curl_init with echo's before and after, just in case it was a combination of the call with something else on the page.

So I started searching for "curl_init fails".  I didn't find anything.  I found one site that said the curl_exec function would fail silently and to call curl_error, but that didn't do me any good because execution stopped before I could call curl_error.  After digging through various search results and not finding anything, I decided to check the manual again for anything I missed.  I forgot the link, so I searched for just "curl_init" again.  This time, the SECOND search result caught my eye.  Someone was reporting an error:
Fatal error: Call to undefined function: curl_init()
I couldn't get any errors at all, but I hoped this would give me some insight.  Sure enough, apparently curl can be turned off, and one of the posters suggested running phpinfo() in a test page to see if it said anything about curl.  If it didn't, then curl was disabled.  Well, phpinfo() definitely didn't say anything about curl on my server.  Further down in the forum page, I found that there is yet another library I have to install called libcurl, and that even then I may have to recompile the PHP library myself to allow it to use it.  Gotta love those linux developers.  Here's to hoping that it's already compiled properly.

There should be a GUI configuration utility for PHP that has an "enable curl" checkbox.  If I check that, it should download the appropriate library if I don't already have it.  Oh, wait.  That's if the developers wanted the app to be user friendly.  We're talking linux here, not Windows, so no chance of that.  So let's do some more searching.  Searching through the Ubuntu Software Center for libcurl doesn't seem to give it to me.  Lots of references for various languages, but none for php.  Searching for just curl, however, turns up CURL module for php5, which is apparently in a library called php5-curl, so I installed that.  Now, after restarting the web service (sudo service apache2 restart) the phpinfo() call does have a curl section.  Yee-haw, I don't have to recompile anything!

I still have errors, but we're much much closer.  Now it is apparently able to download the file, or at least thinks it does, and is giving me permission denied trying to open it.  Checking the cache folder, there aren't any files in there at all, so I'm thinking it didn't really download it at all.  It turns out the fopen lines that are failing are actually opening it for write, which I suppose is supposed to create the file.  So I guess now I have to dig through permissions again.  I hate linux file permissions.

Ok, this time the Ubuntu GUI actually worked the way I expected it to.  I had to change permissions for Other on the cache directory to create and delete.  I don't know which "other" is trying to do it, though.  I don't know if Apache or PHP has its own user that I could set up or not.  If so, it would make sense to set permissions for just that user or it's group.  Of course, it looks like you can't do that on a list of random users, so you would have to make this other user the owner or something.  Oh, well.  I'm not worrying about it now.

Like I said in the beginning, the Zazzle Store Gallery seems more what I want.  The Zazzle Widget seems built around displaying a small number of items on a post or in the sidebar of your page, whereas the Zazzle Store Gallery seems built toward letting you display your entire zazzle gallery as the primary focus of a page, and that is what I want to do.  Because eventually I will have to merge cafepress and zazzle together into a single user interface.  I'll let you know how that works out.  In the meantime, I loaded the gallery plugin and it works fine.  It couldn't have been the permissions, because I only changed them for the one cache directory that the widget was running.  And the code changes couldn't have affected the gallery plugin either.  So the only change that makes sense is enabling curl.

So, that's it for today's adventure.  I hope it was helpful and that it will save you the pain I went through to get it working.

No comments:

Post a Comment