【问题标题】:Cron job failed in Google App Engine Flexible environmentGoogle App Engine 柔性环境中的 Cron 作业失败
【发布时间】:2017-09-30 19:25:31
【问题描述】:

我正在从 Google App engine Standard Environment to Flexible environment 迁移我的 PHP 应用程序。

我的应用程序在数据库和发送网格上运行良好。但是 Cron 作业失败了。

我找不到在 GAE Flexible 环境中运行 Cron 作业时错过的内容。我提供了示例应用程序代码 here

app.yaml

runtime: php
env: flex

runtime_config:
document_root: web

handlers:

- url: /crontest
script: crontest.php

- url: .*
script: index.php

#[START env]
env_variables:
MYSQL_DBNAME: CRONDB
MYSQL_USER: root
MYSQL_PASSWORD: root123
MYSQL_CONNECTION: /cloudsql/project-id:us-central1:testphp7
#[END env]

#[START cloudsql_settings]
# Use the connection name obtained when configuring your Cloud SQL instance.
beta_settings:
cloud_sql_instances: "project-id:us-central1:testphp7"
#[END cloudsql_settings]

cron.yaml

- description: cron test
url: /crontest
schedule: every day 17:00
timezone: Asia/Kolkata

web/connection.php

<?php    
    $con = new mysqli(null,$_SERVER['MYSQL_USER'],$_SERVER['MYSQL_PASSWORD'],$_SERVER['MYSQL_DBNAME'],null,$_SERVER['MYSQL_CONNECTION']);
?>

web/crontest.php

<?php

include "connection.php";

$ATERM_spcallstmt="INSERT INTO SAMPLE(TEST_NO)VALUES('9876')";
$con->query($ATERM_spcallstmt);
?>

web/index.php

<?php
echo " Test Cron in FE";
?>

建表查询:

CREATE TABLE SAMPLE(TEST_NO VARCHAR(250));

来自 API 控制台的日志

18:57:00.000172.18.0.3 - - [02/May/2017:13:27:00 +0000] "GET /crontest.php HTTP/1.1" 404 162 "-" "AppEngine-Google; (+http://code.google.com/appengine)"
{
textPayload: "172.18.0.3 - - [02/May/2017:13:27:00 +0000] "GET /crontest.php HTTP/1.1" 404 162 "-" "AppEngine-Google; (+http://code.google.com/appengine)" "
insertId: "epwcgng8mcw86z"
resource: {…}
timestamp: "2017-05-02T13:27:00Z"
labels: {…}
logName: "projects/project-id/logs/appengine.googleapis.com%2Fstdout"
}

我得到 HTTP 404 & Cron 失败。

请帮我解决这个问题。

提前致谢。

【问题讨论】:

标签: php google-app-engine cron app-engine-flexible


【解决方案1】:

看起来 cron 正在尝试访问 /web/crontest.php,在您的情况下这是不正确的路径。我怀疑你还有旧的 cron 配置?

【讨论】:

  • 感谢 Takashi,我解决了这个问题,我添加了 $_SERVER['HTTP_X_APPENGINE_CRON'] =true;在 crontest.php 中。工作中。我重新编辑了我的帖子
猜你喜欢
  • 1970-01-01
  • 2015-08-01
  • 1970-01-01
  • 2019-04-24
  • 2021-03-23
  • 2019-11-01
  • 2018-11-28
  • 2013-07-15
  • 1970-01-01
相关资源
最近更新 更多