Has anyone had any luck finding some good code to connect to Amazon's S3 service? All of the PHP samples in the S3 Getting Started Guide apparently require various pear packages to be installed and I don't have that kind of access to the server which is PHP 4.4.x. The docs and php samples on Amazon.com leave a lot to be desired. At the moment, this is as far as I get:
Fatal error: Cannot instantiate non-existent class: http_request in /blah/blah/blah/www/wsrcreative.com/s3/bucketList4.php on line 3
The sample file here complains about Crypt/HMAC.php being missing.
I've tried this class like this:
<?
require_once 'AmazonS3Rest.php'; // my name for his file
$ar = new AmazonS3REST('wsrcreative');
$ar->aws_key = '123*****PLE234234';
$ar->aws_secret = 'al/AERELKJFAEXAMPLE/+234adlkj';
$ar->debug = true;
$result = $ar->list_bucket();
print_r($result);
?>
It just times out with this output:
string_to_sign
GET
Tue, 24 Mar 2009 09:43:48 +0000
/mybucket/
Query
GET ?max-keys=15 HTTP/1.1
Host: mybucket.s3.amazonaws.com
Authorization: AWS 123*****PLE234234:GFvAlS6Z02Xow8UEBnjve829lJg=
Date: Tue, 24 Mar 2009 09:43:48 +0000
I've tried modifying this script to list a bucket but it never appears to exit the file reading loop. I think it blocks on fgets somehow.
I've also tried a NuSoap approach like so:
<?php
require_once 'nusoap/nusoap.php';
// Create the client instance
$wsdl_url = 'https://s3.amazonaws.com/doc/2006-03-01/AmazonS3.wsdl';
// Create the client instance
$client = new soapclient($wsdl_url);
// Check for an error
$err = $client->getError();
if ($err) {
// Display the error
echo '<p><b>Constructor error: ' . $err . '</b></p>';
// At this point, you know the call that follows will fail
}
// Call the SOAP method
$result = $client->call('ListBucket', array('Bucket' => 'mybucket')); // this bucket is world-readable so no credentials are necessary
// Check for a fault
if ($client->fault) {
echo '<p><b>Fault: ';
print_r($result);
echo '</b></p>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<p><b>Error: ' . $err . '</b></p>';
print_r($client->response);
} else {
// Display the result
print_r($result);
}
}
?>
The results:
Error: HTTP Error: Unsupported HTTP response status 405 Method Not Allowed (soapclient->response has contents of the response)
HTTP/1.1 405 Method Not Allowed x-amz-request-id: EDAFA7AC120E8047 x-amz-id-2: yzLDZCkVCuJlCh84nPx6S57mHlbT6VvYapD6Ls7nATvhKjIITc9e7QYs2tmPmdNs Content-Type: application/xml Transfer-Encoding: chunked Date: Tue, 24 Mar 2009 09:53:55 GMT Server: AmazonS3 MethodNotAllowedThe specified method is not allowed against this resource.OBJECTPOSTEDAFA7AC120E8047PUTyzLDZCkVCuJlCh84nPx6S57mHlbT6VvYapD6Ls7nATvhKjIITc9e7QYs2tmPmdNs
As you can see, I've been trying quite a few things with no luck. If anyone knows the secret to connecting to S3 in PHP4 without extra libraries, I'd sure love to know what it is.