11

I have a PHP script that is called via a cron job, with the results sent to my email address:

"php /path/to/cron.php"

I only echo errors, otherwise nothing is outputted by me. This way I can get an error report when things go wrong. The problem is, I receive an email with ever cron execution, that only has the HTTP headers in it:

X-Powered-By: PHP/5.2.10
Content-type: text/html

This is obviously a pain, receiving multiple emails every few minutes. All I'd like to see are emails for cron jobs where I've echo'd something.

I want to keep the email being generated by the cron job if possible (instead of sending the email in-script). And I don't want to run it via wget, because my host counts that against my bandwidth.

All my searching has only shown me how to set headers, not remove/suppress the default ones. Am I going about this wrong?

4 Answers 4

14

Try this

php -q /path/to/cron.php

From here: http://www.php.net/manual/en/features.commandline.php#24970

4
  • 3
    I knew it had to be something incredibly easy, 'cause I already tried the hard stuff :) Thanks Joel Commented Oct 20, 2009 at 5:18
  • According to php.net/manual/en/features.commandline.php#74088 the -q option was deprecated in 5.2, and -- should be used.
    – Barmar
    Commented Apr 22 at 23:36
  • It's also only used in CGI mode, it shouldn't have any effect on a cron job.
    – Barmar
    Commented Apr 22 at 23:37
  • I can confirm that the -q flag fixes the issue in 7.3. We could have tried the -- approach instead, but instinctively I preferred the flag fix. (I didn't want to try too many things, because I need to pass the command to the server owner and wait overnight for a scheduled job to trigger).
    – halfer
    Commented Apr 23 at 18:35
0

Using this full command it will work first in configuration file call the your php file will be executed

php -c /home1/sam/public_html/php.ini /home1/sam/public_html/sam_RFID/Android/Email.php

Just Check It.

0

If you're using cPanel, just put the syntax as following:

php /home/<User>/public_html/cron.php >/dev/null 2>&1
1
  • Your solution negates all output. Not what OP requested.
    – Mavelo
    Commented Apr 8, 2018 at 7:13
-1

Helpful note for others researching a very similar issue: Additionally, it should be noted that any trailing newlines or whitespace after a closing php tag will cause a cron job to produce seemingly blank output, even if headers are silenced.

?>

Many people choose to omit their php closing tag for this reason.

1
  • How is this a "similar issue"? Additional lines might not cause the same problem than having headers
    – Nico Haase
    Commented Apr 26 at 6:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.