我在运行(正确)运行cron作业时遇到问题。
我创建了一个调用mail()
的(非常大,但是没有任何东西)的php页面<?
mail('my@email.com', 'subject', 'test');
mail('other@address.com', 'subject', 'test');
?>
然后我创建了我的cron作业,它运行该文件。 crontab -e中的代码行如下:
12 0 * * * /opt/lampp/bin/php /opt/lampp/htdocs/atlantis/application/controllers/cron.php
如果我从终端运行命令/ opt / lampp / bin / php /opt/lampp/htdocs/atlantis/application/controllers/cron.php,我会收到一封发给自己的电子邮件。但是,如果我从cron作业运行相同的行,则它不起作用。
我的下一站是检查日志。我用sSMTP运行Ubuntu。
Apr 16 11:49:17 drew-Virtual crontab[4722]: (drew) END EDIT (drew) //EDITED CRON
//Calling cron.php file from terminal
Apr 16 11:49:31 drew-Virtual sSMTP[4791]: Creating SSL connection to host
Apr 16 11:49:32 drew-Virtual sSMTP[4791]: SSL connection using RSA_AES_128_CBC_SHA1
Apr 16 11:49:34 drew-Virtual sSMTP[4791]: Sent mail for drew@drew-Virtual (221 ip-173-201-180-143.ip.secureserver.net closing connection) uid=1000 username=drew outbytes=444
Apr 16 11:49:34 drew-Virtual sSMTP[4794]: Creating SSL connection to host
Apr 16 11:49:35 drew-Virtual sSMTP[4794]: SSL connection using RSA_AES_128_CBC_SHA1
Apr 16 11:49:37 drew-Virtual sSMTP[4794]: Sent mail for drew@drew-Virtual (221 ip-173-201-180-143.ip.secureserver.net closing connection) uid=1000 username=drew outbytes=454
//I successfully received 2 emails, one to my work account, one to my personal account
//Calling cron.php from cron
Apr 16 11:50:01 drew-Virtual cron[857]: (drew) RELOAD (crontabs/drew)
Apr 16 11:51:01 drew-Virtual CRON[4808]: (drew) CMD (/opt/lampp/bin/php /opt/lampp/htdocs/atlantis/application/controllers/chron.php)
Apr 16 11:51:01 drew-Virtual sSMTP[4810]: Creating SSL connection to host
Apr 16 11:51:02 drew-Virtual sSMTP[4810]: SSL connection using RSA_AES_128_CBC_SHA1
Apr 16 11:51:04 drew-Virtual sSMTP[4810]: Sent mail for drew@drew-Virtual (221 ip-173-201-180-143.ip.secureserver.net closing connection) uid=1000 username=drew outbytes=698
//I did not receive any emails
你可以看到它只试图发送1封电子邮件,我认为失败,因为我从未收到过。但是,它没有告诉我它失败的原因,也没有任何其他线索。我还注意到cron作业中的outbytes比命令行中的outbytes大。
最后,php文件拥有完整的rwx权限,适合所有人。
答案 0 :(得分:2)
问题是PHP是作为apache模块运行的,而不是PHP-CGI。我想作为一种解决方法,我可以使用像
这样的东西lynx -dump http://www.somedomain.com/cron.php
对于我的使用,我最终安装了php5-cli,然后只需将cron作业更改为
php /path/to/file.php
修好了。