cancel
Showing results for 
Search instead for 
Did you mean: 

php and cron

Superuser
Superuser
Posts: 2,565
Thanks: 262
Fixes: 5
Registered: 06-04-2007

php and cron

Hi all

Wondering if there is anyone around that can help me. I have written some php scripts to run from cron on a web host's server (not PlusNet). When the scripts have run I end up with an email from the cron daemon with
X-Powered-By: PHP/4.4.1

Content-type: text/html

I think the email is only getting sent because there is output from the job to report.

This hasn't been a problem so far, but now a script I'm writting will need to run every 15 minutes. This would lead to a lot of unnecessary emails.

So my question is, does anyone know how to stop php when run from cron from producing this output?

Thanks

Phil
4 REPLIES
Community Veteran
Posts: 14,469
Registered: 30-07-2007

php and cron

Just add 2>&1 >/dev/null to the end of the line in cron and all output will be discarded and no email will be generated.

15 * * * * /usr/local/bin/php $HOME/php/script.php 2>&1 >/dev/null
Superuser
Superuser
Posts: 2,565
Thanks: 262
Fixes: 5
Registered: 06-04-2007

php and cron

I know that one, but the script could produce some legitimate output that I would want emailing to me (though I could code round that). It was more just the php version info I wanted to get rid of so that the email wouldn't be sent when there is no other output.

Phil
Community Veteran
Posts: 14,469
Registered: 30-07-2007

php and cron

Use php -q to surpress the HTTP header output

The other options can be found by running php -h at a shell prompt.

However, some versions of php differ in what they do, I'm running php 5.0.4 on my linux box and it does not output the HTTP header info or have a -q option.

If php -q does not work, try the following:

15 * * * * /usr/local/bin/php $HOME/php/script.php | fgrep -v "X-Powered-By" | fgrep -v "Content-type"

the -v in fgrep reverses the test so it allows through anything that does not match the text - i.e. your errors.
Superuser
Superuser
Posts: 2,565
Thanks: 262
Fixes: 5
Registered: 06-04-2007

php and cron

Cheers Peter. The -q did it.

Phil