0

I'm setting up a PHP app with Cloud Firestore on Google Cloud Platform based on https://github.com/googleapis/google-cloud-php-firestore.

After deploying to App Engine, I see that "new FirestoreClient();" doesn't work, but the same code runs normally on localhost. How can I fix this?

The code:

index.php

<?php

require_once 'vendor/autoload.php';
use Google\Cloud\Firestore\FirestoreClient;

echo "Hello Firestore";

$firestore = new FirestoreClient();
$collectionReference = $firestore->collection('boards');
$documentReference = $collectionReference->document("b-1");
$snapshot = $documentReference->snapshot();
$data = $snapshot->data();
var_dump($data);

echo "Goodbye Firestore";
?>

app.yaml

runtime: php72

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: /images
  static_dir: images

- url: /stylesheets
  static_dir: stylesheets

Google Cloude Platform logs

GET 200 385 B 1,3 s Chrome 74 / I GET 200 385 B 1,3 s Chrome 74
nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /tmp/google-config/nginx.conf:3 
A GET 200 107,58 KiB 2 ms Chrome 74 /images/logo.png A GET 200 107,58 KiB 2 ms Chrome 74

composer.json

{
    "name": "projects/plzwork",
    "description": "i don't know...",
    "type": "project",
    "license": "Apache-2.0",
    "require": {
        "google/cloud": "^0.101.0",
        "grpc/grpc": "^1.19"
    }
}

Output with localhost

Hello Firestore

array(4) { ["headline"]=> string(1) "b" ["amount_of_threads"]=> int(1) ["description"]=> string(22) "Flood and nothing else" ["content_type"]=> string(7) "default" }

Goodbye Firestore

Output with Google Cloud Platform

Hello Firestore

Database view

Juan Lara
  • 6,454
  • 1
  • 22
  • 31
Kara Sick
  • 3
  • 4
  • 1
    Since the execution is stopped after the "Hello Firestore" output, it appears an error is occurring. Check your application logs in the Cloud Console for more details. Once you have found the error, share it in this question if you're unable to fix it yourself. – jdp May 13 '19 at 16:39

1 Answers1

2

I think you might be missing a php.ini file to enable the grpc extension which Cloud Firestore requires:

php.ini

extension=grpc.so

Include this file with your application. Check out these docs:

Also, you mentioned not seeing any errors in your logs. The errors might've been reported in different files that aren't visible by default. Here's how to view them in the console:

enter image description here

Juan Lara
  • 6,454
  • 1
  • 22
  • 31
  • Now i see authentication warning on localhost, and nothing new on gcloud( – Kara Sick May 13 '19 at 16:57
  • Do you receive any errors? See the logs https://cloud.google.com/appengine/docs/standard/php7/writing-application-logs – Juan Lara May 13 '19 at 17:10
  • For some reason only informational log that I show above and after some time - response 204 for logo.png in head title – Kara Sick May 13 '19 at 17:27
  • One more thing to verify is the project ID. You might want to also remove the line `putenv("GCLOUD_PROJECT=moondepth");`. Is `moondepth` the correct project ID and does the project have a `boards/b-1` document? – Juan Lara May 13 '19 at 17:31
  • Project ID is "moondepth" and document exists, but when i change id to thing as "sdgsadwgf" - on localhost i get "Hello Firestore\n NULL\n Goodbye Firestore\n" and on GCloud i get "Hello Firestore\n" without errors – Kara Sick May 13 '19 at 19:56
  • Last thing I can think of is to double check your `composer.json` file. Make sure `google/cloud-firestore` is in there and that the file is getting deployed to App Engine. Otherwise, it seems like there should be some kind of error reported after `Hello Firestore`. – Juan Lara May 13 '19 at 20:28
  • i wrote code from - github.com/googleapis/google-cloud-php-firestore tutorial, and also edit my question with composer.json – Kara Sick May 14 '19 at 20:57
  • I think I was able to replicate your issue. Are you missing the `php.ini` file in your deployment? Updated my answer. – Juan Lara May 15 '19 at 00:02