【发布时间】:2019-09-30 15:21:45
【问题描述】:
我正在基于https://github.com/googleapis/google-cloud-php-firestore 在Google Cloud Platform 上使用Cloud Firestore 设置PHP 应用。
部署到 App Engine 后,我看到“new FirestoreClient();”不起作用,但相同的代码在 localhost。我该如何解决这个问题?
代码:
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"
}
}
使用本地主机输出
你好 Firestore
array(4) { ["headline"]=> string(1) "b" ["amount_of_threads"]=> int(1) ["description"]=> string(22) "洪水,仅此而已" ["content_type"]=> 字符串(7) "默认" }
再见 Firestore
使用谷歌云平台输出
你好 Firestore
【问题讨论】:
-
由于在“Hello Firestore”输出后停止执行,因此出现错误。在 Cloud Console 中查看您的应用日志以了解更多详情。发现错误后,如果您无法自行修复,请在此问题中分享。
标签: php google-app-engine google-cloud-platform google-cloud-firestore google-app-engine-php