我正在尝试运行基于 SendGrid 和 cron 的自动邮件服务。我已经尝试了所有可能的组合来使 PHP 解释器运行我的脚本,虽然 cron 日志说该作业每分钟执行一次,但我定义的日志文件仍然是空的,并且没有收到任何电子邮件,但是当我通过浏览器访问页面时,一切正常。
mydev.com 是我在我的机器上使用的虚拟主机,我没有对 php 配置进行任何更改(最大执行时间等)。
另外,我在网上做了研究,我安装了 php5-cli,以及所有需要的依赖项。
下面是我在终端中输入 sudo crontab -e 后添加到 cron 文件中的行:
* * * * * php /var/www/mydev/dev/mailServiceTest.php >> /var/www/mydev/CRON_LOG.txt 2> /dev/null
* * * * * /usr/bin/php /var/www/mydev/dev/mailServiceTest.php >> /var/www/mydev/CRON_LOG.txt 2> /dev/null
* * * * * /usr/bin/php http://mydev.com/dev/mailServiceTest.php >> /var/www/mydev/CRON_LOG.txt 2> /dev/null
* * * * * /usr/bin/lynx http://mydev.com/dev/mailServiceTest.php >> /var/www/mydev/CRON_LOG.txt 2> /dev/null
这是 cron 日志的输出:
Apr 15 15:13:01 oleg-Lenovo-G580 CRON[8948]: (root) CMD (/usr/bin/php http://mydev.com/dev/mailServiceTest.php >> /var/www/mydev/CRON_LOG.txt 2> /dev/null)
Apr 15 15:13:01 oleg-Lenovo-G580 CRON[8947]: (root) CMD (php /var/www/mydev/dev/mailServiceTest.php >> /var/www/mydev/CRON_LOG.txt 2> /dev/null)
Apr 15 15:13:01 oleg-Lenovo-G580 CRON[8949]: (root) CMD (/usr/bin/php /var/www/mydev/dev/mailServiceTest.php >> /var/www/mydev/CRON_LOG.txt 2> /dev/null)
Apr 15 15:13:01 oleg-Lenovo-G580 CRON[8953]: (root) CMD (/usr/bin/lynx http://mydev.com/dev/mailServiceTest.php >> /var/www/mydev/CRON_LOG.txt 2> /dev/null)
Apr 15 15:14:01 oleg-Lenovo-G580 CRON[8964]: (root) CMD (/usr/bin/lynx http://mydev.com/dev/mailServiceTest.php >> /var/www/mydev/CRON_LOG.txt 2> /dev/null)
Apr 15 15:14:01 oleg-Lenovo-G580 CRON[8966]: (root) CMD (php /var/www/mydev/dev/mailServiceTest.php >> /var/www/mydev/CRON_LOG.txt 2> /dev/null)
Apr 15 15:14:01 oleg-Lenovo-G580 CRON[8965]: (root) CMD (/usr/bin/php http://mydev.com/dev/mailServiceTest.php >> /var/www/mydev/CRON_LOG.txt 2> /dev/null)
Apr 15 15:14:01 oleg-Lenovo-G580 CRON[8970]: (root) CMD (/usr/bin/php /var/www/mydev/dev/mailServiceTest.php >> /var/www/mydev/CRON_LOG.txt 2> /dev/null)
Apr 15 15:15:01 oleg-Lenovo-G580 CRON[8992]: (root) CMD (/usr/bin/php /var/www/mydev/dev/mailServiceTest.php >> /var/www/mydev/CRON_LOG.txt 2> /dev/null)
Apr 15 15:15:01 oleg-Lenovo-G580 CRON[8994]: (root) CMD (php /var/www/mydev/dev/mailServiceTest.php >> /var/www/mydev/CRON_LOG.txt 2> /dev/null)
Apr 15 15:15:01 oleg-Lenovo-G580 CRON[8993]: (root) CMD (/usr/bin/php http://mydev.com/dev/mailServiceTest.php >> /var/www/mydev/CRON_LOG.txt 2> /dev/null)
Apr 15 15:15:01 oleg-Lenovo-G580 CRON[8998]: (root) CMD (/usr/bin/lynx http://mydev.com/dev/mailServiceTest.php >> /var/www/mydev/CRON_LOG.txt 2> /dev/null)
Apr 15 15:16:01 oleg-Lenovo-G580 CRON[9009]: (root) CMD (/usr/bin/php /var/www/mydev/dev/mailServiceTest.php >> /var/www/mydev/CRON_LOG.txt 2> /dev/null)
Apr 15 15:16:01 oleg-Lenovo-G580 CRON[9011]: (root) CMD (php /var/www/mydev/dev/mailServiceTest.php >> /var/www/mydev/CRON_LOG.txt 2> /dev/null)
Apr 15 15:16:01 oleg-Lenovo-G580 CRON[9012]: (root) CMD (/usr/bin/lynx http://mydev.com/dev/mailServiceTest.php >> /var/www/mydev/CRON_LOG.txt 2> /dev/null)
Apr 15 15:16:01 oleg-Lenovo-G580 CRON[9010]: (root) CMD (/usr/bin/php http://mydev.com/dev/mailServiceTest.php >> /var/www/mydev/CRON_LOG.txt 2> /dev/null)
任何帮助深表感谢!。
O。
编辑:
下面是应该执行的代码:
<?php
require_once($_SERVER['DOCUMENT_ROOT'] . '/classes/mailingService.php');
$myMail = new mailingService();
$myMail->execute();
$myMail->outputDuration();
?>
现在,即使我添加 'echo 1;' 在文件的开头或结尾处,没有什么变化,并且输出文件 CRON_LOG.txt 保持为空