【问题标题】:PHP AWS Cron Job Post from Worker Tier To Server Tier URLPHP AWS Cron Job Post 从 Worker Tier 到 Server Tier URL
【发布时间】:2016-09-14 13:22:10
【问题描述】:

我基本上想要做的是定期在我的服务器层 Web 应用程序中运行 PHP 脚本。为此,我创建了一个 Worker Tier 应用程序并将以下代码添加到 cron.yaml 中,如 Running cron jobs on Amazon Web Services (AWS) Elastic Beanstalk 中所述。

version: 1
cron:
 - name: "email-job"          # required - unique across all entries in this file
   url: "https://www.example.com/cron_test.php"              # required - does not need to be unique
   schedule: "* */10 * * *"    # required - does not need to be unique

根据脚本,cron_test.php 会每 10 分钟向我发送一封电子邮件(cron_test.php 没有任何问题,因为它可以在我的浏览器中完美运行)。

由于这不起作用,我尝试将 url 更改为本地的。

version: 1
cron:
 - name: "email-job"          # required - unique across all entries in this file
   url: "/send_mails.php"              # required - does not need to be unique
   schedule: "* */10 * * *"    # required - does not need to be unique

send_email.php 页面中,我像这样简单地重定向到服务器层中所需的网址。

header("Location: https://www.example.com/cron_test.php");

奇怪的是,我仍然没有收到来自我的服务器层应用程序的任何电子邮件。当我检查我的日志时,我可以看到以下内容

127.0.0.1 (-) - - [18/May/2016:04:58:59 +0000] "POST /send_email.php HTTP/1.1" 302 - "-" "aws-sqsd/2.3"

虽然 302 表明确实发生了重定向,但我仍然没有收到任何电子邮件。我究竟做错了什么?还有其他方法可以实现我的目标吗?

【问题讨论】:

    标签: php amazon-web-services cron


    【解决方案1】:

    您可以通过获取 url 的内容而不是将守护进程发送到带有 header 标记的 url 来解决此问题:

    <?php
    echo file_get_contents("https://www.example.com/cron_test.php");
    ?>
    

    【讨论】:

      猜你喜欢
      • 2017-06-25
      • 2017-09-04
      • 2016-01-22
      • 2014-08-16
      • 2014-09-12
      • 2014-06-18
      • 2014-11-27
      • 2016-06-30
      • 1970-01-01
      相关资源
      最近更新 更多