[英]How to auto start PHP worker after deployment to GAE standard environment
在我的 app.yaml 文件中,我在https://cloud.google.com/appengine/docs/standard/php7/runtime#application_startup上抛出文档后有以下配置
service: xxxx-xxxx
runtime: php72
entrypoint: php test.php
instance_class: F2
automatic_scaling:
min_instances: 1
max_instances: 2
env_variables:
TEST: "xxxxx"
目录结构
- test.php
- app.yaml
问题:PHP 脚本在部署后不运行,但仅在我点击给定的 .appspot.com URL 时运行。
我想要的是在部署后自动启动脚本。
谢谢 。
如果您希望在部署应用程序时自动运行代码,则需要指定在部署期间运行的最少实例数量,否则 App Engine 将等到它向 URL 发出请求以启动实例。
您需要做的是在 main 中的任何路由之外编写代码,然后在 app.yaml 中实现自动缩放
这里有一个来自Hello_World 示例的应用程序示例:
索引.php
<?php
echo "hello world!";
syslog(LOG_INFO, 'Authorized access');
// Handle your warmup logic for your app.
switch (@parse_url($_SERVER['REQUEST_URI'])['path']) {
case '/_ah/warmup':
echo "Warmup successful";
syslog(LOG_INFO, 'Authorized Warmup');
break;
// Other handlers
// ...
}
?>
应用程序.yaml
runtime: php72
inbound_services:
- warmup
automatic_scaling:
min_idle_instances: 2
min_instances: 2
实例数将等于您希望应用程序在部署时运行的次数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.