Google Cloud PubSub with PHP - 如何在 App Engine 服务器端安装 类?

Google Cloud PubSub with PHP - how to install classes on the App Engine server side?

我正在尝试使用 Google 消息传递系统,但我在开始之前就失败了。 我试图从一个超级简单的应用程序开始,它只传输 "hello world" 消息然后捕获它。将其保存在数据库中,其他任务将在此服务启动后完成 运行.

但是我不能得到它 work.I 得到错误:

[my-app].appspot.com is currently unable to handle this request. HTTP ERROR 500

在日志中,我看到了问题:

PHP Fatal error: Class 'Google\Cloud\PubSub\PubSubClient' not found in /base/data/home/apps/g~[my-app]/20170809t182312.403268501910529191/printHello.php on line 14

第 14 行是:$pubsub = new PubSubClient([ 从 google 文档中复制粘贴

考虑:

我错过了什么?我阅读了在 cloud.google 上找到的所有页面。 ...以及我在互联网上找到的所有内容,但似乎没有人遇到过类似的问题。所以这一定是我做错了或没有做的非常简单的事情。有什么建议吗?

Google Cloud PubSub 不是 by default enabled in GAE. You need to add it to your app code. From Pure PHP:

You can include other pure PHP libraries with your application by putting the code in your application's directory, which is the same directory that contains your app.yaml file.

For example, you can create a symbolic link in your application's directory that points to a library's directory. That link is then followed and that library gets included in your application when you deploy to App Engine.

You can also include PHP libraries by specifying php.ini directives and including PHP include statements in your code. However, the preferred alternative is to use a PHP dependency management tool such as Composer.

我会在 Intellij IDEA 中检查 library/class 在您本地系统上的位置,并将其符号链接到您的应用程序目录中。 可能 有必要调整 use 语句 and/or 符号链接源目录以使事情顺利进行。

注意:我是 Python,不是 PHP 用户,所以请对此持保留态度。