Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Google Cloud Storage for PHP?

So ive followed the guide on how to use GCS on their site: https://developers.google.com/appengine/docs/php/googlestorage/

But the following code does not work. I cannot access my bucket, and the CloudStorageTools is not even found.

require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php';
use google\appengine\api\cloud_storage\CloudStorageTools;

// check if GCS bucket if writable
$my_bucket = 'gs://my_bucket/';
$check1 = is_writable($my_bucket); //returns nothing

class_exists("CloudStorageTools"); //returns false

I also added google_app_engine.allow_include_gs_buckets into the php.ini file. Still no support for GCS.

Anyone have some running code they could share?

like image 847
viezel Avatar asked Nov 02 '22 09:11

viezel


1 Answers

I think it may have something to do with permissions set to your bucket. Make sure you added your app account email Application Settings -> Service Account Name.

I ported my app with no issues and using Smarty to write into and include from the bucket. I did not have to declare:

require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php';
use google\appengine\api\cloud_storage\CloudStorageTools;

and the app reads and writes to the bucket with no problems.

I have had however issues with some WordPress porting, when although the bucket existed and had properly setup access permission, for some reason app throws a Fatal Error and I can see it in the app logs, that application was trying to access the cloud storage via gs:// wrapper.

Hope that helps.

like image 143
mal Avatar answered Nov 09 '22 10:11

mal