Return to PHP and SimpleDB
It’s been a very long time — last August, to be precise — since Amazon’s SimpleDB was first mentioned. At the time, it was being investigated as a potential method of implementing full text search. A lot of time, effort and money has passed under the bridge since then — not to mention that search functionality was eventually implemented with Solr. But it’s now time to return to SimpleDB, but for a completely different application; to store user profile and session information required to provide secured, session-based access to the Intellog website. After re-reading all the SimpleDB-related blog posts, I now realize there wasn’t a lot of detail on server configuration for PHP/SimpleDB, so that will be fleshed out now. The most relevant post was Software Mirepoix, and it’s worth taking another look to provide some context for the notes below. The objective is to establish a more-or-less standard approach to deploying PHP/SimpleDB apps — at least an approach which can be migrated to the production environment when the time comes.
But first…there was the question of which specific PHP/SimpleDB library to use. There were three options identified; the PHP Library for Amazon SimpleDB, the php-sdb library by David Meyers, and finally the Zend Framework (ZF). I couldn’t find a lot of relevant information on the use of ZF with SimpleDB, despite a post to the SimpleDB Discussion Forum. David Meyers’ library looks great, but it’s strength — masking the underlying complexity of SimpleDB interactions — was actually seen as a barrier to clear understanding of the SimpleDB interface, at least for now. By default, therefore, the Amazon-supplied PHP library was the way to go.
There have been quite a few updates to the Amazon’s PHP Library since it was last employed, so the latest version (amazon-simpledb-2009-04-15-php5-library.zip) was downloaded, and unzipped into a folder of the same name (minus the .zip, of course). Within this folder, there was another called src, and the ReadMe.html. Within src, in turn, there was a folder called Amazon. The latter folder was the one copied from C:\Program Files\PHP\include, and the include_path line in php.ini was modified by appending C:\Program Files\PHP\include to its existing definition.
.config.inc.php was put in C:\Program Files\PHP\include\Amazon\SimpleDB. This is the same place as the library class files Client.php, Model.php etc., rather than in the folder(s) where the Roundabout application is located. Because .config.inc.php contains the Amazon Web Services (AWS) access key and the secret identifier, it was felt it was better to keep it out of the web-accessible hierarchy folders under DocumentRoot. Incidentally, .config.in.php also contains the __autoload function which according to the inline documentation "is responsible for loading classes of the library on demand". It’s not 100% clear what this means, but the net effect of the function is to make all the classes in the library available to the application code.
To provide an initial test of the configuration, one of the samples provided as part of the library – ListDomainsSample.php — was copied over to the app.E.intellog.com/var/www/html folder. Just one line needed to be changed; include_once('.config.inc.php'), needed to be modified to read include_once('Amazon/SimpleDB/.config.inc.php'). Keep in mind, the include_path in php.ini, modified above, tells PHP where to start looking for a class when it can’t be found in the local folder, so there is no need to be more explicit with the include_once statement.
Oh yes, and it’s also necessary to define the $request variable in ListDomainsSample.php, but that’s a one liner, as per $request = new Amazon_SimpleDB_Model_ListDomainsRequest(); But with that done, the code lit right up and was able to produce a listing of domains associated the SimpleDB account. If you have any questions or comments, please do not hesitate to contribute them below, and thanks for reading!
Code Shavings Executing the sample application above initially resulted in an error message which, amongst other things, said "[u]nable to find the socket transport ’ssl’ - did you forget to enable it when you configured PHP?" Some Googling revealed this is due the lack of the OpenSSL extension in the PHP configuration. This problem was addressed by upgrading PHP in the development environment from the original, installed using php-5.2.6-win32-installer.msi, to a slightly more up-to-date version, installed with php-5.2.9-2-win32-installer.msi available from php.net. The real trick, though, was to make sure when it got to the step in the installation where it extensions are selected, that OpenSSL was one of them. Somehow, I missed that the first time around. The installation script even configures php.ini so it knows about the OpenSSL extension. ♦ To this point, I wasn’t clear on precisely the way included files worked in PHP. Turns out the file Amazon\SimpleDB\Client.php (for example) contains a single class called Amazon_SimpleDB_Client. Note the name of the class mirrors the directory structure, except the slashes have been replaced with underscore characters. This pattern appears to be adopted for all files in the Amazon library. ♦ As with OpenSSL, the installation script for PHP is smart enough to know to add extension=php_xsl.dll to the php.ini file.
Posted on 26th May 2009
Under: Developers' Journal | No Comments »

With the marketing effort well underway, it was time to pay some attention to building up the body of of documentation available for the
Onramp is Intellog’s next generation search engine — like Google