My favorites | Sign in
Repository Home Source
Clone Information
Members

SabreDAV with Amazon S3 support

Access Amazon S3 via WebDAV protocol from a simple PHP Hosting Server

Up- and downloads are passed through stream to stream without temporarily storing GETs and PUTs on the hosting server first. New files and folders inherit storage redundancy ['STANDARD', 'REDUCED_REDUNDANCY'] and some basic ACL ['private', 'public-read', 'public-read-write', 'authenticated-read'] settings from their parents.

Requirements

You need a Web Server with PHP Version >= 5.3 and < 6 for all features to work. PHP Version >= 5.2 and < 6 works without using the Persistence Entity Manager (cache). PHP v6 does not seem to work with SabreDAV yet.

Be sure to get the amazons3 branch from this repository.

$ hg clone https://1meref-sabredav-amazons3.googlecode.com/hg/ 1meref-sabredav-amazons3
$ cd 1meref-sabredav-amazons3
$ hg update amazons3

The Amazon SDK for PHP v1.2.2 is included with this repository.

Example setup

Assuming you have installed this SabreDAV clone in "SabreDAV/" in your web server's htdocs directory and set up an apache server (.htaccess) like this...

RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ server.php [L]

This is the most basic example for a "server.php" to list all buckets from the account in the root folder:

<?php
require_once('SabreDAV/lib/AWS/sdk.class.php');
require_once('SabreDAV/lib/Sabre.autoload.php');

date_default_timezone_set('YOUR_TIME_ZONE'); // like 'GMT'

$server = new Sabre_DAV_Server(
  new Sabre_DAV_S3_Tree(
    new Sabre_DAV_S3_Account(),
    new AmazonS3(
      'YOUR_KEY',
      'YOUR_SECRET_KEY'
)));

$server->setBaseUri('/');
$server->exec();

This is an example "server.php" to set up a bucket as the root node, support node caching (Entity Manager) to the local filesystem and automatically update the cache after node access (Plugin) with a minimum entity lifetime of 300s, a maximum of 2 simultaneously working update threads, which have a processing time limit of 120s, and an unlimited number of threads (requests) allowed to add to the queue at the same time:

<?php
require_once('SabreDAV/lib/AWS/sdk.class.php');
require_once('SabreDAV/lib/Sabre.autoload.php');

date_default_timezone_set('YOUR_TIME_ZONE'); // like 'GMT'

$server = new Sabre_DAV_Server(
  new Sabre_DAV_S3_Tree(
    new Sabre_DAV_S3_Bucket(
      'YOUR_BUCKET_NAME'),
    new AmazonS3(
      'YOUR_KEY',
      'YOUR_SECRET_KEY'),
    new Sabre_DAV_S3_EntityManagerFS(
      'YOUR_CACHE_DIR')
));

$server->addPlugin(
 new Sabre_DAV_S3_Plugin(
  new Sabre_DAV_S3_Plugin_Queue_FS(
    'YOUR_QUEUE_FILENAME',
    2,
    -1),
  300,
  120
));

$server->setBaseUri('/');
$server->exec();

There is no separate documentation yet. You need to look at the source code for PHP Doc comments. Also head over to the SabreDAV project home for more information on how to customize your server and set up authentication for example. If you use the web server's authentication, be sure to allow unauthenticated access from the loopback device (127.0.0.1) for the update plugin to work.

Known issues

  • The latest Amazon PHP SDK (1.0.1) has a bug which prevents the deletion of folders. See Amazon Forum. Patch available at github.
  • Possible issues if you have more than 1000 objects in the bucket.
  • EU Region does not work with DNS-Style bucket access. Set to Standard region (REGION_US_E1) - accessed IP will be in Ireland as well.
  • Inheritance problems if you create files in folders manually where the folder has no object itself. Maybe use the first existent parent object (and create an object for future reference).
  • Slow responsiveness, especially in Windows Explorer as it does a lot of PROPFIND requests, until caching has been implemented.
  • Possible update problem when adding new updates faster than they can be processed.

Further development

  • A new Tree Class to speed things up in nested folders and support native Amazon Copy requests for copy/move operations.
  • A new Directory class to mount different buckets or all buckets from an account.
  • Make Copy and Move requests for folders faster by batching S3 requests.
  • Support renaming of non empty folders.
  • Use Amazon SDK's native caching or implement a new one to speed things up and prevent possible issues with Amazon's "eventual consistency".
  • Support locking.
  • Support all WebDAV properties. Possibly by storing them as x-amz-meta- headers.
  • Add an object to hold default Storage Class settings for buckets (probably just a dot "." as object name).
  • Support an array of strings in Account constructor to ease instantiation of buckets if only a fixed subset of buckets shall be listed.
  • Generate a Doc and write a Wiki.
  • Improve update Plugin to not always update all children of an accessed node's parent.
  • Extend the caching to allow for configurable (size / time) local file storage.
  • Support for complex ACL.
  • Integrate Amazon ACL / IAM and SabreDAV's ACL.
  • Make separate projects for the Entity Manager and Shared Queue and include them as a library.
Powered by Google Project Hosting