Amazon S3 + PHP = Awesome image hosting solution

Recently I have been looking for a solution to allow users of notpopular.com to have photo albums of unlimited size. Its a popular trend in social networks, and its way cooler then the 5 tiny images that are allowed on notPopular.com (1.0)

There are many technical problems that associated with having this kind of open system. One of the biggest problems is storage (disk space), and load on the web server. Each image takes up space on the hard drives, and requires attention from the web server when an image is requested, taking attention and CPU from other more important processes.

After looking at several options, I came across Amazon S3 (Simple Storage Service). Amazon S3 is an online storage web service offered by Amazon Web Services. It provides unlimited storage through a simple web services interface. Data can be easily stored and retrieved at any time, from anywhere on the web. Amazon charges in proportion to the amount of data stored and applies charges for sending and receiving data. A perfect solution for what I’m looking to do!

S3 would store the data, and would handle the load of the requests coming from users, allowing my web server to focus on more important tasks like PHP processing and MySQL queries.

Here is the price break down for amazon S3 usage:

  • Storage
    • $0.15 per GB-Month of storage used
  • Data Transfer
    • $0.10 per GB – all data transfer in
    • $0.18 per GB – first 10 TB / month data transfer out
    • $0.16 per GB – next 40 TB / month data transfer out
    • $0.13 per GB – data transfer out / month over 50 TB
    • $0.01 per 1,000 PUT or LIST requests
    • $0.01 per 10,000 GET and all other requests

Using the calculator tool they have, and looking at the notpop data and projected traffic, my monthly costs would be around $20 a month, and even if things doubled in time, it would still only be $40 a month. Very reasonable for the speed and reliability that a company like Amazon offers.

I found some great php classes to work with S3, particilarly one from Geoffrey P. Gaudreault over at neurofuzzy.net

I am also planing on using some CNAME records on the notPop server to mask the amazon URL. Should be easy to do.

Last night I started to sew Amazon S3 into the pending notPop 2.0 code base. I will make some follow up posts about how it goes once I really start using it.