PHP 5 已达到支持终止期限,并将于 2026 年 1 月 31 日
弃用。弃用后,您将无法部署 PHP 5 应用,即使您的组织之前曾使用组织政策重新启用旧版运行时的部署也是如此。现有的 PHP 5 应用在
弃用日期之后将继续运行并接收流量。我们建议您
迁移到最新支持的 PHP 版本。
配置文件
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
服务的每个版本都在 .yaml
文件中定义,此文件提供相应服务和版本的名称。YAML 文件通常与其定义的服务同名,但这不是必需的。如果您要部署一项服务的多个版本,则可以在同一目录中创建多个 yaml 文件,每个文件对应一个版本。
通常,您可以为每项服务创建一个目录,以包含相应服务的 YAML 文件和关联的源代码。可选的应用级配置文件(dispatch.yaml
、cron.yaml
、index.yaml
和 queue.yaml
)包含在顶级应用目录中。以下示例展示了三项服务。在 service1
和 service2
中,源文件与 YAML 文件处于同一级别。在 service3
中,有两个版本的 YAML 文件。

对于小型简单项目,应用的所有文件都可以位于一个目录中:

每个 YAML 文件都必须包含版本参数。如需定义默认服务,您可以在文件中明确声明参数 service: default
或者不作声明。
每项服务的配置文件都定义了特定服务/版本的扩缩类型和实例类别。使用的扩缩参数取决于您指定的扩缩类型。如果未指定扩缩类型,则默认为自动扩缩。app.yaml
参考文档部分介绍了扩缩和实例类别设置。
对于每项服务,您还可以指定相应设置,以将网址请求映射到特定脚本以及识别静态文件,进而提高服务器效率。这些设置也包含在 yaml 文件中,并在 app.yaml
参考文档部分进行了说明。
default 服务
每个应用都有一项默认服务。您可以在 app.yaml
中使用 service: default
设置定义默认服务,但并不强制要求这样做。与服务相关的所有配置参数都可以应用于默认服务。
可选配置文件
以下配置文件可以对应用于应用中所有服务的可选功能进行控制:
要将这些配置文件的更新部署到 App Engine,请从这些文件所在的目录中运行以下命令:
gcloud app deploy [CONFIG_FILE]
示例
以下示例演示了如何为具有以下三项服务的应用配置 YAML 文件:处理网络请求的默认服务,以及另外两项处理移动请求和进行后端处理的服务。
首先定义一个名为 app.yaml
的配置文件,该文件将处理所有与 Web 相关的请求:
runtime: php55
api_version: 1
threadsafe: true
如果此应用的 Google Cloud 控制台项目 ID 是 simple-sample
,则此配置将创建具有自动扩缩功能且公共地址为 https://simple-sample.uc.r.appspot.com
的默认服务。
接下来,假设您要创建一项服务来处理移动网络请求。考虑到移动用户的需求(在本示例中),最长等待延迟时间仅为一秒,并且我们将始终具有至少两个实例处于空闲状态。如需进行此项配置,您需要创建一个 mobile-frontend.yaml
配置文件,其中包含以下内容:
service: mobile-frontend
runtime: php55
api_version: 1
threadsafe: true
automatic_scaling:
min_idle_instances: 2
max_pending_latency: 1s
此文件创建的服务随后可通过 https://mobile-frontend-dot-simple-sample.uc.r.appspot.com
进行访问。
最后,添加一项名为 my-service
的服务来处理静态后端工作。这可能是一项持续作业,用于将数据从 Datastore 导出到 BigQuery。工作量相对固定,因此您在任意给定时间只需要一项常驻服务。此外,这些作业需要进行大量内存处理,因此您需要内存配置更高的服务。如需进行此项配置,您需要创建一个 my-service.yaml
配置文件,其中包含以下内容。
service: my-service
runtime: php55
api_version: 1
threadsafe: true
instance_class: B8
manual_scaling:
instances: 1
此文件创建的服务随后可通过 https://my-service-dot-simple-sample.uc.r.appspot.com
进行访问。
请注意 manual_scaling:
设置。instances:
参数会告知 App Engine 要为此服务创建多少实例。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-09-04。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[[["\u003cp\u003eEach service version is defined in a \u003ccode\u003e.yaml\u003c/code\u003e file, which specifies the service name and version, and multiple versions can be defined in separate YAML files within the same directory.\u003c/p\u003e\n"],["\u003cp\u003eServices typically have their own directories containing YAML files and source code, while optional application-level configuration files like \u003ccode\u003edispatch.yaml\u003c/code\u003e, \u003ccode\u003ecron.yaml\u003c/code\u003e, \u003ccode\u003eindex.yaml\u003c/code\u003e, and \u003ccode\u003equeue.yaml\u003c/code\u003e are placed in the top-level app directory.\u003c/p\u003e\n"],["\u003cp\u003eEvery YAML file requires a version parameter, and the default service can be defined explicitly with \u003ccode\u003eservice: default\u003c/code\u003e or by omitting the service parameter.\u003c/p\u003e\n"],["\u003cp\u003eEach service's configuration file defines scaling type and instance class, with automatic scaling as the default if not specified.\u003c/p\u003e\n"],["\u003cp\u003eOptional configuration files like \u003ccode\u003edispatch.yaml\u003c/code\u003e controls routing and \u003ccode\u003ecron.yaml\u003c/code\u003e schedules tasks for all services in an app.\u003c/p\u003e\n"]]],[],null,["# Configuration Files\n\nEach version of a service is defined in a `.yaml` file, which gives the name of\nthe service and version. The YAML file usually takes the same name as the\nservice it defines, but this is not required. If you are deploying several\nversions of a service, you can create multiple yaml files in the same directory,\none for each version.\n\nTypically, you create a directory for each service, which contains the service's\nYAML files and associated source code. Optional application-level configuration\nfiles (`dispatch.yaml`, `cron.yaml`, `index.yaml`, and `queue.yaml`) are\nincluded in the top level app directory. The example below shows three services.\nIn `service1` and `service2`, the source files are at the same level as the YAML\nfile. In `service3`, there are YAML files for two versions.\n\nFor small, simple projects, all the app's files can live in one directory:\n\nEvery YAML file must include a version parameter. To define the default service,\nyou can explicitly include the parameter `service: default` or leave the service\nparameter out of the file.\n\nEach service's configuration file defines the scaling type and instance class\nfor a specific service/version. Different scaling parameters are used depending\non which type of scaling you specify. If you do not specify scaling, automatic\nscaling is the default. The scaling and instance class settings are described in\nthe [`app.yaml`\nreference](/appengine/docs/legacy/standard/php/config/appref#scaling_elements)\nsection.\n\nFor each service you can also specify settings that map URL requests to specific\nscripts and identify static files for better server efficiency. These settings\nare also included in the yaml file and are described in the\n[`app.yaml` reference](/appengine/docs/legacy/standard/php/config/appref)\nsection.\n\n### The default service\n\nEvery application has a single default service. You can define the default\nservice in the `app.yaml` with the setting\n`service: default`, but it isn't necessary to do this. All configuration\nparameters relevant to services can apply to the default service.\n\n### Optional configuration files\n\nThese configuration files control optional features that apply to all the\nservices in an app:\n\n- [`dispatch.yaml`](/appengine/docs/legacy/standard/php/reference/dispatch-yaml) overrides routing default rules by sending incoming requests to a specific service based on the path or hostname in the URL.\n- [`queue.yaml`](/appengine/docs/legacy/standard/php/config/queueref) configures both push queues and pull queues.\n- [`index.yaml`](/appengine/docs/legacy/standard/php/configuring-datastore-indexes-with-index-yaml) specifies which indexes your app needs if using Datastore queries.\n- [`cron.yaml`](/appengine/docs/legacy/standard/php/config/cronref) configures regularly scheduled tasks that operate at defined times or regular intervals.\n\nTo deploy updates of these configuration files to App Engine, run the\nfollowing command from the directory where they are located: \n\n gcloud app deploy [CONFIG_FILE]\n\n### An example\n\nHere is an example of how you would configure YAML files for an application that\nhas three services: a default service that handles web requests, plus two more\nservices that handle mobile requests and backend processing.\n\nStart by defining a configuration file named `app.yaml` that will handle all\nweb-related requests: \n\n runtime: php55\n api_version: 1\n threadsafe: true\n\nIf the Google Cloud console project ID for this app is `simple-sample` then\nthis configuration would create a default service with automatic scaling and a\npublic address of `https://simple-sample.uc.r.appspot.com`.\n\nNext, assume that you want to create a service to handle mobile web requests.\nFor the sake of the mobile users (in this example) the max pending latency will\nbe just a second and we'll always have at least two instances idle. To configure\nthis you would create a `mobile-frontend.yaml` configuration file. with the\nfollowing contents: \n\n service: mobile-frontend\n runtime: php55\n api_version: 1\n threadsafe: true\n\n automatic_scaling:\n min_idle_instances: 2\n max_pending_latency: 1s\n\nThe service this file creates would then be reachable at `https://mobile-frontend-dot-simple-sample.uc.r.appspot.com`.\n\nFinally, add a service, called `my-service` for handling static backend work.\nThis could be a continuous job that exports data from Datastore to BigQuery. The\namount of work is relatively fixed, therefore you simply need 1 resident service\nat any given time. Also, these jobs will need to handle a large amount of\nin-memory processing, thus you'll want services with an increased memory\nconfiguration. To configure this you would create a `my-service.yaml`\nconfiguration file with the following contents. \n\n service: my-service\n runtime: php55\n api_version: 1\n threadsafe: true\n\n instance_class: B8\n manual_scaling:\n instances: 1\n\nThe service this file creates would then be reachable at\n`https://my-service-dot-simple-sample.uc.r.appspot.com`.\n\nNotice the `manual_scaling:` setting. The `instances:` parameter tells App\nEngine how many instances to create for this service."]]