0

I'm trying to create a bucket in Google Cloud Storage using PHP client library but bucket is not being created (FYI: no gcs function working at all) and even its not returning an error code or exception so I can debug the issue.

  1. I have gRPC and Protobuf installed
  2. Using compute engine instance with full permissions granted
  3. Enabled the billing for project and also Storage API is Enabled

If need anything else ask me in the comment. Any hint / clue much appreciated.

Here's the code I'm using:

require 'vendor/autoload.php';

# Imports the Google Cloud client library
use Google\Cloud\Core\ServiceBuilder;
use Google\Cloud\Storage\StorageClient;

function create_bucket($bucketName, $options = [])
{
    $config = [
        'projectId' => 'abc-def-agen-1553542096432'
    ];
    $storage = new StorageClient($config);
    //var_dump($storage);
    $bucket = $storage->createBucket($bucketName, $options);
    //var_dump($bucket); //this returns nothing
    printf('Bucket created: %s' . PHP_EOL, $bucket->name()); // this prints nothing
}
create_bucket("kjdsnuiew345asd");
ericcco
  • 741
  • 3
  • 15
Rehan
  • 408
  • 1
  • 6
  • 17
  • you have confirmed on your Cloud Console that the buckets have not been created?. Because it can take a moment to be created and the code is not waiting for it so the var "$bucket" could not be initialized when you print it. – Mayeru Aug 02 '19 at 10:37
  • I have checked and confirmed no bucket created. – Rehan Aug 02 '19 at 10:53
  • is pointing to the right project-id?. have you installed the lib?, confirmed that is entering in "create_bucket"? if the function encounter an error it should be reflected on the logs, if you aren't seeing any errors it might be because: is not being executed or is printing the logs somewhere else. Also, if you are running it from a CE you could try this: $storage = new StorageClient(); $bucket = $storage->createBucket($bucketName); it should take the default settings, along with the project is in. – Mayeru Aug 02 '19 at 11:25
  • yes project-id is correct and have installed the lib. What I noticed is $storage = new StorageClient(); is being initiated but after this line >> $bucket = $storage->createBucket($bucketName); code stops working and nothing execute just blank page. – Rehan Aug 02 '19 at 11:46
  • You're certain there's no error (perhaps not displayed, or even suppressed)? Have you checked the server logs? – jdp Aug 02 '19 at 13:56
  • what do you mean with "code stops working" ? it crash?, doesn't print the next lines? terminates the function?. and where are you seeing this "blank page"? the browser?. Does your application depend on the creation of the bucket to initialize? because that is not recommended -> https://cloud.google.com/storage/quotas#buckets – Mayeru Aug 05 '19 at 15:50
  • Thanks everyone I got it fixed. On compute instance it was not reporting any error but when I configured on local and start testing the exception appeared and I resolved it. – Rehan Aug 06 '19 at 16:48

0 Answers0