从工作者层到服务器层URL的PHP​​ AWS Cron作业发布

时间:2016-05-18 07:39:17

标签: php amazon-web-services cron

我基本上想要做的是定期在我的服务器层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表示确实发生了重定向,但我仍然没有收到任何电子邮件。我究竟做错了什么?有没有其他方法可以实现我的目标?

1 个答案:

答案 0 :(得分:0)

您可以通过获取网址的内容而不是使用标记标记将deamon发送到网址来解决此问题:

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