如何在Google Cloud Platform上使用Firestore正确部署PHP应用程序?

时间:2019-05-13 16:11:45

标签: php google-app-engine google-cloud-platform google-cloud-firestore google-app-engine-php

我正在基于https://github.com/googleapis/google-cloud-php-firestore Google Cloud Platform 上使用 Cloud Firestore 设置 PHP应用

部署到 App Engine 后,我看到“ 新的FirestoreClient(); ”不起作用,但是相同的代码通常可以在 localhost < / strong>。我该如何解决?

代码:

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平台日志

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"
    }
}

使用localhost输出

  

Hello Firestore

     

array(4){[“” headline“] => string(1)” b“ [” amount_of_threads“] => int(1)   [“ description”] =>字符串(22)“洪水,仅此而已”   [“ content_type”] =>字符串(7)“默认”}

     

再见消防站

使用Google Cloud Platform输出

  

Hello Firestore

Database view

1 个答案:

答案 0 :(得分:1)

我认为您可能缺少php.ini文件来启用Cloud Firestore所需的grpc扩展名:

php.ini

extension=grpc.so

将此文件包含在您的应用程序中。查看以下文档:

此外,您提到在日志中未看到任何错误。错误可能是在默认情况下不可见的其他文件中报告的。在控制台中查看它们的方法如下:

enter image description here