0
votes

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

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.

What I want is to auto start the script after deployment.

Thanks .

1

1 Answers

1
votes

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.

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

Here you have an example of my application taken form the Hello_World sample:

index.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

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.