【问题标题】:AppEngine BigQuery PHP libraries not implicit in runtime?AppEngine BigQuery PHP 库在运行时不隐含?
【发布时间】:2019-09-12 15:41:34
【问题描述】:

我正在尝试从 AppEngine 上的 PHP 进行 BigQuery 调用。是否假设 BigQuery PHP 库必须包含在部署文件中,并且它们在运行时中不隐式可用?

简单实例化示例:

<?php
use Google\Cloud\BigQuery\BigQueryClient;
$bigQuery = new BigQueryClient();
?>

然后是不可避免的错误:

[error] 20#20: *2 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught Error: Class 'Google\Cloud\BigQuery\BigQueryClient' not found in /srv/index.php:5 Stack trace: #0 {main} thrown in /srv/index.php on line 3" while reading response header from upstream, client: , server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/tmp/google-config/php-fpm.sock:"

是否期望这些库是隐含的过于假设性?

编辑:这是部署目录中的composer.json 文件(我非常困惑,因为app.yaml 应该是库的声明位置,不是吗?)

????我什至不确定如何指定版本或只是一般的 BQ。

{
    "require": {
        "google/cloud": "^0.99.0"
    }
}

【问题讨论】:

  • 你能给我们看看你的 composer.json 文件吗?你在那里添加了 BQ 库吗?
  • @Pentium10 可能就是问题所在。诚然,我对这个作曲家有点迷茫,但问题已随该文件更新。
  • composer 看起来不错,确保在您的 php 文件中包含 vendor/autoload.php
  • @Pentium10,谢谢,vendor/* 文件是否需要包含在部署包中?另外,是否假设所述目录在 CWD 中?

标签: php google-app-engine google-bigquery


【解决方案1】:

假设 BigQuery PHP 库必须包含在 部署文件,它们在 运行时间?

没错,您应该使用 BigQuery PHP client library

在 Google Cloud Platform 文档的 article 中查看有关其安装使用的信息(切换到“PHP”标签查看代码示例) .

编辑:

我已经复制了您的情况,遵循 GCP tutorial 将一个简单的 PHP HelloWorld 应用程序部署到 Google App Engine。我修改了 composer.json 文件,使其与您的匹配,并使用相同的代码行来包含 BigQuery 库。

我可以通过要求 Composer 的自动加载器来解决这个问题。这可以通过在 index.php 文件中添加以下行来实现:

require 'vendor/autoload.php';

这是我的 composer.json 文件:

{
    "require": {
        "google/cloud": "^0.99.0"
    }
}

这是我的 index.php 文件:

<?php
  require 'vendor/autoload.php';

  use Google\Cloud\BigQuery\BigQueryClient;
  $bigQuery = new BigQueryClient();

  echo "Hello World!";
?>

如果有帮助,请告诉我。

【讨论】:

  • 谢谢。我有 PHP 库,问题是它们是否需要与文件捆绑以进行部署,或者它们是否隐式包含在 PHP AppEngine 运行时中。
  • 云客户端库未隐式安装在应用引擎上。话虽如此,您无需显式部署供应商目录,因为只要有 composer.json 文件,我们就会代表您运行composer install
猜你喜欢
  • 2019-05-02
  • 1970-01-01
  • 1970-01-01
  • 2021-01-08
  • 1970-01-01
  • 2018-07-04
  • 2015-10-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多