0
votes

I have a php app running on several instances of Google Compute Engine (GCE). The app allows users to upload images of various sizes, resizes the images and then stores the resized images (and their thumbnails) in the storage disk and their meta data in the database.

What I've been trying to find is a method for storing the images onto Google Cloud Storage (GCS) through the php app running on GCE instances. A similar question was asked here but no clear answer was given there. Any hints or guidance on the best way for achieving this is highly appreciated.

1
I have been searching and reading for the past couple of hours about google API and gsutil. It seems like I can either use the PHP google API or gsutil. The images will be uploaded initially to my php app for resizing/creating the thumbnails. Which is better/more efficient ? using gsutil or the php google api to copy the files to the google cloud storage instance ?Seme1

1 Answers

4
votes

You have several options, all with pros and cons.

Your first decision is how users upload data to your service. You might choose to have customers upload their initial data to Google Cloud Storage, where your app would then fetch it and transform it, or you could choose to have them upload it directly to your service. Let's assume you choose the second option, and you want users to stream data directly to your service.

Your service then transforms the data into a different size. Great. You now have a new file. If this was video, you might care about streaming the data to Google Cloud Storage as you encode it, but for images, let's assume you want to process the whole thing locally and then store it in GCS afterwards.

Now we have to get a file into GCS. It's a PHP app, and so as you have identified, your main three options are:

  1. Invoke the GCS JSON API through the Google API PHP client.
  2. Invoke either the GCS XML or JSON API via custom code.
  3. Use gsutil.

Using gsutil will be the easiest solution here. On GCE, it automatically picks up appropriate credentials for your service account, and it's got several useful performance optimizations and tuning that a raw use of the API might not do without extra work (for example, multithreaded uploads). Plus it's already installed on your GCE instances.

The upside of the PHP API is that it's in-process and offers more fine-grained, programmatic control. As your logic gets more complicated, you may eventually prefer this approach. Getting it to perform as well as gsutil may take some extra work, though.

This choice is comparable to copying files via SCP with the "scp" command line application or by using the libssh2 library.

tl;dr; Using gsutil is a good idea unless you have a need to handle interactions with GCS more directly.