-
Notifications
You must be signed in to change notification settings - Fork 9
/
README
114 lines (82 loc) · 3.78 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
aS3StreamWrapper: a better Amazon S3 stream wrapper for PHP
ABOUT
This is an Amazon S3 stream wrapper. It lets your PHP code use
fopen(), file_put_contents(), opendir(), readdir(), closedir(),
stat(), copy() and friends via Amazon S3. Unlike most wrappers there
is full support for subdirectories (not just directory listings of
entire buckets).
LIMITATIONS
Be aware that files are buffered entirely in memory which will lead to
out of memory errors on files larger than your PHP memory limit.
For our use cases this currently makes a lot of sense, but
perhaps we'll add support for buffering on the local drive instead
as an option specified when registering a protocol or creating
a stream context. It's not hard compared to the stuff we've
covered already.
UNUSUAL FEATURES
* You can make subdirectories and sub-subdirectories (most S3
wrappers don't support S3's native features for listing things
with a prefix and a limit)
* You can register the wrapper more than once under different names
* You can subclass and extend the wrapper class properly
* Caching support for fast read access to the first 8K of each file
* Extensive unit tests
USAGE
Registering the stream wrapper is easy:
$wrapper = new aS3StreamWrapper();
$wrapper->register(array('protocol' => 's3',
'acl' => AmazonS3::ACL_PUBLIC,
'key' => 'your key id',
'secretKey' => 'your secret key',
'region' => AmazonS3::REGION_US_W1));
Now you can open files over S3 with, for instance:
fopen("s3://bucketname/subdir/filename.txt", "w");
Note that the first directory level is the bucket name.
You must use mkdir() to create a new bucket. Calling
mkdir() and rmdir() for subdirectories belong the bucket
level is not really necessary but we support it so that
your code works naturally.
See lib/wrapper/aS3StreamWrapperTest.php for extensive examples
of proper usage.
Note that you can register *more than one* protocol name,
with *different* options. Which means that you can copy
files from region to region or with different ACL settings
(public vs. private).
Many (but not all) PHP functions accept stream wrapper URLs.
See:
http://php.net/manual/en/book.stream.php
For the official PHP documentation on this. There are
many
Our stream wrapper class is in lib/wrapper along with
its tests. lib/vendor contains a recent snapshot of the
official AWS PHP SDK from Amazon.
CACHING
S3 is great at delivering content to end users
and scaling the storage of content in general, but you don't want to do
many reads of entire S3 objects in rapid succession just to peek at
their headers to determine image dimensions, file type, etc. The
optional cache feature addresses this problem. You supply the cache
object.
In addition to the options demonstrated above and in the tests,
you can specify a 'cache' option, which must point to a cache object
that supports get($key), set($key, $data, $timeout-in-seconds),
has($key) and remove($key) methods (hint: any subclass of sfCache is
cool). This cache is used to store the first 8K of every file and also
the results of stat().
Consider using memcache or even a MySQL cache that is fast and local
to your servers. Of course, all of your servers must use the cache
consistently to get consistent results.
SYMFONY
Although we built this for Symfony and Apostrophe, the wrapper has
no dependencies on Symfony or Apostrophe. But if you add this
folder to your plugins/ folder in a Symfony 1.x project and
add it to ProjectConfiguration in the usual way, you'll be able
to autoload the stream wrapper. Just FYI.
WARNING
Use at your own risk. There is no warranty, express or implied.
LICENSE
Copyright 2011 P'unk Avenue LLC. Released under the BSD license.
Built for Apostrophe: apostrophenow.com
CONTACT
Questions? Contact us via http://github.com/punkave
Also follow us at http://punkave.com/ and @punkave