【问题标题】:Firestore Client' not found未找到 Firestore 客户端
【发布时间】:2019-05-03 08:07:52
【问题描述】:

我是 PHP 和 Firebase 的新手。我试图在 php 网站上使用 firestore。

use Google\Cloud\Firestore\FirestoreClient;

ini_set("display_errors", 1);
ini_set("track_errors", 1);
ini_set("html_errors", 1);
error_reporting(E_ALL);

initialize();




function initialize()
{
    // Create the Cloud Firestore client
    $db = new FirestoreClient();
    printf('Created Cloud Firestore client with default project ID.' . PHP_EOL);
}

但是有一个致命错误:在第 37 行的 /var/www/html/test.php 中找不到类 'Google\Cloud\Firestore\FirestoreClient'

我遵循了快速入门教程 - https://firebase.google.com/docs/firestore/quickstart

我正在使用带有 PHP 5.6 的 debian 9 VPS

【问题讨论】:

    标签: php firebase google-cloud-firestore


    【解决方案1】:

    无法从您的test.php 文件访问类库。

    使用引导程序加载 Google\Cloud\Firestore\FirestoreClient 或手动将其包含在您的脚本中。

    【讨论】:

    • 我实际上是手动包含使用 Google\Cloud\Firestore\FirestoreClient;在我的 php 脚本中
    • 你应该尽可能多地分享你的代码,以明确你包含了什么以及你是如何做到的
    【解决方案2】:

    你确定你仔细关注all of the steps了吗?

    即,请检查您是否已添加库:

    composer require google/cloud-firestore
    

    并且您已将以下内容添加到文件顶部:

    use Google\Cloud\Firestore\FirestoreClient;
    

    【讨论】:

    • 是的,这两件事都做了
    【解决方案3】:

    问题已解决。如果有人有同样的问题。我在页面顶部添加了require 'vendor/autoload.php';。并确保将extension=grpc.so 添加到两个 php.ini 文件(一个在 apache 2 文件夹内,另一个在 cli 文件夹内)并重新启动 apache。这是我的新代码

    use Google\Cloud\Firestore\FirestoreClient;
    require 'vendor/autoload.php';
    ini_set("display_errors", 1);
    ini_set("track_errors", 1);
    ini_set("html_errors", 1);
    error_reporting(E_ALL);
    
    initialize();
    
    function initialize()
    {
        // Create the Cloud Firestore client
        $db = new FirestoreClient();
        printf('Created Cloud Firestore client with default project ID.' . PHP_EOL);}
    

    【讨论】:

      猜你喜欢
      • 2020-03-27
      • 2015-02-20
      • 2016-03-02
      • 2017-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-24
      相关资源
      最近更新 更多