[英]How to auto start PHP worker after deployment to GAE standard environment
In my app.yaml file I have the below config after going throw the document on https://cloud.google.com/appengine/docs/standard/php7/runtime#application_startup在我的 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"
Directory structure目录结构
- test.php
- app.yaml
Problem: PHP script doesn't run after deployment but only runs when I hit the .appspot.com URL given.问题:PHP 脚本在部署后不运行,但仅在我点击给定的 .appspot.com URL 时运行。
What I want is to auto start the script after deployment.我想要的是在部署后自动启动脚本。
Thanks .谢谢 。
If you want your code to be autorun when you deploy your application you need to specify a minimum amount of instances to be run during the deploy, otherwise App Engine will wait until a request it's made to the URL to start an instance.如果您希望在部署应用程序时自动运行代码,则需要指定在部署期间运行的最少实例数量,否则 App Engine 将等到它向 URL 发出请求以启动实例。
What you need to do is to write your code outside of any route in your main and then implement automatic scaling in your app.yaml您需要做的是在 main 中的任何路由之外编写代码,然后在 app.yaml 中实现自动缩放
Here you have an example of my application taken form the Hello_World sample :这里有一个来自Hello_World 示例的应用程序示例:
index.php索引.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
// ...
}
?>
app.yaml应用程序.yaml
runtime: php72
inbound_services:
- warmup
automatic_scaling:
min_idle_instances: 2
min_instances: 2
The number of instances will be equal to the number of times that you want your application to be run at the deployment.实例数将等于您希望应用程序在部署时运行的次数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.