开发者

Extra email from Cron Daemon when running an email list script

I have a PHP script that sends out a bi-weekly reminder to subscribers. Each time it sends out the email it also sends out an email that comes in from "Cron Daemon." When I first wrote the script, it didn't send this email, but now it does. I have a few questions about this.

This is what the email says:

Set-Cookie: PHPSESSID=((random letters and numbers here));开发者_开发知识库 path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-type: text/html
  1. What does this email mean?
  2. Why is this email being sent?
  3. Is there a way to stop the scrip from sending this email?


Cron reads the stdout/stderr of the command that gets executed, if something is written then cron sends an E-Mail.

I guess the php-executable is compiled as "cgi" or "fcgi" so it emits those headers by default.

To solve this you have apparently three possible solutions:

  • Use the "cli" version of PHP
  • Redirect stderr and stdout to /dev/null (that means append > /dev/null 2>&1 to your cron command).
  • Define MAILTO="" (see this page).


My guess is your PHP script is rendering something to the output. If anything gets rendered at all, cron forwards that to the default administrator email.

There's two solutions to this:

1) Fix your PHP script to not output anything at all. This is sometimes harder than it would seem, especially for non-trivial scripts.

2) Prevent the cron script from ever having an output. The drawback to this method is you won't get a notice when the script fails, either. To stop the output, use something like this:

#Before
* * * * * php /path/to/script
#After
* * * * * php /path/to/script > /dev/null 2>&1
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜