简体   繁体   English

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

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

I'm trying to use the Google messaging system but I'm failing before starting. 我正在尝试使用Google消息系统,但在开始之前失败了。 I'm trying to start with a super simple app that only transmit a "hello world" message and then capture it. 我正在尝试从一个超级简单的应用程序开始,该应用程序仅发送“ hello world”消息,然后捕获它。 Saving it in DB and other tasks will be done after this service is up and running. 在启动并运行此服务后,将其保存在数据库中和执行其他任务。

However I can't get it to work.I get the error: 但是我无法使其正常工作。我得到了错误:

[my-app].appspot.com is currently unable to handle this request. [my-app] .appspot.com当前无法处理此请求。 HTTP ERROR 500 HTTP错误500

On logs, I see the problem: 在日志上,我看到了问题:

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 PHP致命错误:在第14行的/base/data/home/apps/g~[my-app]/20170809t182312.403268501910529191/printHello.php中找不到类'Google \\ Cloud \\ PubSub \\ PubSubClient'

Line 14 is: $pubsub = new PubSubClient([ which is copy paste from google documentation 第14行是: $pubsub = new PubSubClient([这是从Google文档复制粘贴

Consider: 考虑:

  • The app is working fine without the: use Google\\Cloud\\PubSub\\PubSubClient; 该应用程序在没有以下情况的情况下运行正常: use Google\\Cloud\\PubSub\\PubSubClient; . I delete everything except an echo "... some text praying to make it work..." and it is displayed. 我删除了echo "... some text praying to make it work..."以外的所有内容, echo "... some text praying to make it work..."并显示出来。 So no problem in app.yaml file or somewhere else. 因此,app.yaml文件或其他地方没有问题。

  • I was able to send a message from the topic detail page and receive it in web-console so all authorizations and enabling are done correct. 我能够从主题详细信息页面发送消息并在网络控制台中接收消息,因此所有授权和启用均正确完成。

  • on local machine, Intellij IDEA recognized the PubSubClient class after I installed beta components. 在本地计算机上,安装了beta组件后,Intellij IDEA识别出PubSubClient类。 The app is not working on local machine, but I did not even try it. 该应用程序无法在本地计算机上运行,​​但我什至没有尝试过。 I want to be able to make it work on the server first time. 我希望能够使其首次在服务器上工作。

  • I checked and all files from local are present on the server as well. 我检查了所有本地文件,并且服务器上也都存在。

What am I missing? 我想念什么? I read all pages I found on cloud.google. 我阅读了在cloud.google上找到的所有页面。 ... and all I found on the internet but it seems nobody had a similar problem. ...以及我在互联网上发现的所有内容,但似乎没有人遇到类似的问题。 So it must be something very simple that I'm doing wrong or have not done. 因此,我做错了或没有做过的事情一定很简单。 Any suggestions? 有什么建议么?

Google Cloud PubSub is not by default enabled in GAE. GAE 默认未启用Google Cloud PubSub。 You need to add it to your app code. 您需要将其添加到您的应用程序代码中。 From Pure PHP : 纯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. 通过将代码放在应用程序的目录中,可以将其他纯PHP库包含在您的应用程序中,该目录与包含app.yaml文件的目录相同。

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. 然后,您会链接到该链接,并且在您将其部署到App Engine时,该库会包含在您的应用程序中。

You can also include PHP libraries by specifying php.ini directives and including PHP include statements in your code. 您还可以通过指定php.ini指令并在代码中包含PHP include语句来包含PHP库。 However, the preferred alternative is to use a PHP dependency management tool such as Composer . 但是,首选的替代方法是使用PHP依赖项管理工具,例如Composer

I'd check in Intellij IDEA where is the library/class located on your local system and symlink it into your app dir. 我将在Intellij IDEA中检入本地系统上的库/类在哪里,并将其符号链接到您的应用程序目录中。 It might be necessary to adjust the use statement and/or the symlink source dir to get things going. 可能需要调整use语句和/或symlink源目录以使事情进展。

Note: I'm a Python, not a PHP user, so take this with a grain of salt. 注意:我是Python,而不是PHP用户,因此请特别注意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM