如何在 Google Cloud Platform 上使用 Firestore 正确部署 PHP 应用程序?
How to properly deploy PHP app with Firestore on Google Cloud Platform?
我正在 PHP 应用程序 中设置 Cloud Firestore Google 云平台 基于 https://github.com/googleapis/google-cloud-php-firestore.
部署到 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"
}
}
用本地主机输出
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
使用Google云平台
输出
Hello Firestore
Database view
我认为您可能缺少 php.ini
文件来启用 Cloud Firestore 需要的 grpc
扩展:
php.ini
extension=grpc.so
将此文件包含在您的申请中。查看这些文档:
另外,您提到在您的日志中没有看到任何错误。错误可能已在默认情况下不可见的不同文件中报告。以下是如何在控制台中查看它们:
我正在 PHP 应用程序 中设置 Cloud Firestore Google 云平台 基于 https://github.com/googleapis/google-cloud-php-firestore.
部署到 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"
}
}
用本地主机输出
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
使用Google云平台
输出Hello Firestore
Database view
我认为您可能缺少 php.ini
文件来启用 Cloud Firestore 需要的 grpc
扩展:
php.ini
extension=grpc.so
将此文件包含在您的申请中。查看这些文档:
另外,您提到在您的日志中没有看到任何错误。错误可能已在默认情况下不可见的不同文件中报告。以下是如何在控制台中查看它们: