php - 我可以在 Google App Engine for Python 上运行 PHP 文件吗?

标签 php python google-app-engine

作为免责声明,我是应用程序开发的新手。

所以我一直在使用 Google App Engine 和 Python 运行时环境来开发这个网站。当我用 HTML 创建一个简单的表单并决定使用 PHP 来存储数据时,出现了问题。当我的应用程序在 Python 中运行时,我是否可以使用 PHP 脚本?

我还注意到GAE现在有PHP运行环境,那么我应该使用它吗?我只使用Python,因为一开始它很容易使用,而且我认为我不需要PHP。

这就是我的 main.py 的样子,如果重要的话:

import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp import template

class MainHandler(webapp.RequestHandler):
  def get (self, q):
    if q is None:
      q = 'index.html'

    path = os.path.join (os.path.dirname (__file__), q)
    self.response.headers ['Content-Type'] = 'text/html'
    self.response.out.write (template.render (path, {}))

def main ():
  application = webapp.WSGIApplication ([('/(.*html)?', MainHandler)], debug=True)
  util.run_wsgi_app (application)

if __name__ == '__main__':
  main ()

最佳答案

不可以,您将无法在 Python 运行时环境中运行 PHP 脚本。如果您的应用程序更容易用 PHP 编写,您可以使用 PHP 运行时环境。

app.yaml中,设置runtime: php,并创建handlers:,其中script:值是一个 PHP 脚本:

applciation: helloworld
version: 1
runtime: php
api_version: 1

handlers:
- url: /.*
  script: helloworld.php

那么helloworld.php可以是PHP脚本,例如:

<?php
  echo 'Hello, world!';
?>

请注意,您可以对 Python 和 PHP 使用相同的 SDK。

关于php - 我可以在 Google App Engine for Python 上运行 PHP 文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22775157/

相关文章:

google-app-engine - 静态内容更改 Google App Engine

google-app-engine - AppEngine 任务队列 : is there a way to determine the queue depth?

Javascript/Ajax(无 jquery!)onreadystatechange 保持 1

python - 从文件中读取两列列表并排序

php - 我应该把这个脚本放在什么目录

python - 带Lambda层的Keras

python - 有没有更简单的方法来更改 pandas 数据框的索引值?

google-app-engine - 如何将 Stackdriver 日志导入 BigQuery

php - CakePHP:无法以纯文本形式发送电子邮件

php - 我在php上的用户定义的navigation()无法正常工作,我无法在代码中找到错误