tpyo / amazon-s3-php-class

A standalone Amazon S3 (REST) client for PHP 5/CURL
1.03k stars 503 forks source link

Make hostname and credentials customisable per request #161

Open codemedic opened 4 years ago

codemedic commented 4 years ago

Most part of the change is to reduce global state, while keeping the API as close to original as possible. Please note that there are breaking changes, but I hope you will find them OK to live with.

I have also taken the liberty of adding a license file to match what is mentioned in composer.json and S3.php, and I have also added my employer to the list of copyrights, considering the amount of changes and the time spent doing them.

There are some tweaks to make examples work better with composer's autoloading. Also changes to those examples to make it load values through environment variables rather than having to edit the files.

I have tested these as much as I can against S3 and an in house implementation of S3 like storage access layer.

codemedic commented 4 years ago

@tpyo forgot to mention that there is also an optimisation to make the examples work against S3 regions that redirects using 307 Temporary Redirect, where we would have had to re-authenticate on receiving the response code. The 307 redirects were particularly a headache as we (rightly) create buckets within the test, and it takes 24Hrs to work without the 307 redirect (for the newly created bucket, if we go to <bucket>.s3.amazonaws.com).

I have changed according to the workaround suggested in AWS docs; rather than always going to [<bucket>.]s3.amazonaws.com the request is sent to a region specific service endpoint. This generally makes things faster as less DNS magic is involved to hit the right endpoint within AWS.

Hostname / endpoint is formulated using the pattern described here