Gallery2, s3fs and Amazon S3

stephen

Joined: 2002-11-20
Posts: 17
Posted: Mon, 2008-05-19 19:56

Hi everyone,

I think I have successfully and efficiently made use of Amazon's S3 service with gallery2. I'm going to post more technical details and code here soon, but I'd like you all to poke at the web page and see if you can discover any problems.

The basic idea is to use s3fs to mount the S3 bucket as a disk on the server. There are several with the same name, I'm using this one:

http://code.google.com/p/s3fs/wiki/FuseOverAmazon

I move the contents of g2data/albums and g2data/cache/derivative/*dat onto the s3fs disk, and reference them using symlinks. I don't move the whole folder and symlink the folder because that's really slow. I also only move the *.dat files from derivative, as the *inc files aren't very big and are read with page loads. The goal was to limit the amount the server talks to S3 and maximize the image requests that go from client to S3.

I also wrote a small python script that redirects requests for images to the S3 version, taking the place of this line from .htaccess. I tried to use embedded gallery, but that turned out to be really slow.

RewriteRule . /gallery2/main.php?g2_view=core.DownloadItem&g2_itemId=%1&g2_serialNumber=%2&g2_fileName=%3 [QSA,L]

There are some downfalls, this probably won't work on shared hosts unless it's an awesome shared host. Also, and it will be clear when I post the code, if the image isn't on S3, the redirect to S3 will fail, and it turns out it's not a guaranteed thing that the image is on S3.

I plan on making this method public, but I'd like to vet it a bit, think of pitfalls I've missed, and clean it up. It's not very complicated.

Here's the S3-ized site. You can confirm that the images are coming from S3 if you open them in a new tab or window.

--- http://abcdgoldfish.stephenskory.com/gallery2/main.php ---

Let me know what you think! Thanks!

 
Stopb

Joined: 2007-07-24
Posts: 2
Posted: Tue, 2008-06-03 10:56

This looks fantastic. Just what I am after, please can you post the code.

Thanks.

 
stephen

Joined: 2002-11-20
Posts: 17
Posted: Tue, 2008-06-03 20:55

I haven't forgotten about posting it here. I'm still feeling things out. After I posted the stuff above I found a couple big problems and I've fixed them, so it's good I didn't do it on my first post. I'll put it up soon!

 
stephen

Joined: 2002-11-20
Posts: 17
Posted: Fri, 2008-06-06 20:41

Hello,

I think I've got it to a point I can make it public. I've put instructions and code on my website:

Step by step instructions:

http://stephenskory.com/s3-with-gallery2

I also have a page with some comments about all of this:

http://stephenskory.com/s3-with-gallery2/s3-with-gallery2-details

Some of what I said in my first post isn't true anymore, particularly the part about images being S3 or not.

I welcome your comments!

 
risoldi

Joined: 2008-09-18
Posts: 1
Posted: Mon, 2008-09-22 16:40

That's great, I'm definitely going to do that. Thanks!

 
rafiks
rafiks's picture

Joined: 2009-07-13
Posts: 44
Posted: Thu, 2010-05-06 12:23

does the same concept work on gallery 3?

 
stephen

Joined: 2002-11-20
Posts: 17
Posted: Thu, 2010-05-06 13:08

rafiks,

I believe it may be possible to apply the same concept to G3, but what I've done is G2-specific. I have actually only played around with G3 so I can't give you any ideas where to start.

Good luck!

 
bromide
bromide's picture

Joined: 2010-08-20
Posts: 28
Posted: Fri, 2010-08-20 15:02

This was actually listed in a spreadsheet of considered features for Gallery3 but evidently wasn't implemented. I created an enhancement request here for it.
Ⓑ® bromide      

 
thefoxbrain

Joined: 2010-01-12
Posts: 28
Posted: Thu, 2010-11-18 10:09

It looks like someone has got this working here...

http://write2it.net/2010/09/an-early-attempt-at-integrating-gallery-3-with-amazons-cloudfront/

...worth taking into account with any future work. Looks like a simple change

 
bromide
bromide's picture

Joined: 2010-08-20
Posts: 28
Posted: Wed, 2010-11-24 18:34

Also here's a thread about Windows Azure, S3, and Gallery 3:

http://gallery.menalto.com/node/99109

˳® bromide