0

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

部署到App Engine后,我看到“ new FirestoreClient(); ”不起作用,但相同的代码在localhost上正常运行。我怎样才能解决这个问题?

编码:

索引.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";
?>

应用程序.yaml

runtime: php72

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

- url: /images
  static_dir: images

- url: /stylesheets
  static_dir: stylesheets

谷歌云平台日志

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

作曲家.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"
    }
}

使用本地主机输出

你好 Firestore

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

再见火库

使用 Google Cloud Platform 输出

你好 Firestore

数据库视图

4

1 回答 1

2

我认为您可能缺少一个php.ini文件来启用grpcCloud Firestore 所需的扩展:

php.ini

extension=grpc.so

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

此外,您提到在您的日志中没有看到任何错误。这些错误可能已在默认情况下不可见的不同文件中报告。以下是在控制台中查看它们的方法:

在此处输入图像描述

于 2019-05-13T16:45:28.363 回答