我從Google App engine Standard Environment to Flexible environment遷移我的PHP應用程序。Google App Engine中的Cron作業失敗靈活的環境
我的應用程序正常工作與數據庫和發送網格。但克倫工作失敗。
我找不到我在GAE靈活的環境中運行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
網/ connection.php
<?php
$con = new mysqli(null,$_SERVER['MYSQL_USER'],$_SERVER['MYSQL_PASSWORD'],$_SERVER['MYSQL_DBNAME'],null,$_SERVER['MYSQL_CONNECTION']);
?>
網/ crontest.php
<?php
include "connection.php";
$ATERM_spcallstmt="INSERT INTO SAMPLE(TEST_NO)VALUES('9876')";
$con->query($ATERM_spcallstmt);
?>
網/ 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失敗。
請幫我解決這個問題。
在此先感謝。
我沒有看到你的app.yaml這個特殊的設置 「cloud_sql_instances」從本指南(https://cloud.google.com/appengine/docs/flexible/python/using-cloud-sql) 看看這有助於。 – ankitk
謝謝ankitk,我解決了這個問題,我添加了$ _SERVER ['HTTP_X_APPENGINE_CRON'] = true;在crontest.php中。現在工作 – Sattanathan