我正在基于https://github.com/googleapis/google-cloud-php-firestore在Google 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