If I echo a statement and no one hears it, does it ever get echoed? (PHP cron job question) If I echo a statement and no one hears it, does it ever get echoed? (PHP cron job question) apache apache

If I echo a statement and no one hears it, does it ever get echoed? (PHP cron job question)


The answer is yes, and the output is mailed to the account that is running the cron task. You can change this in the crontab file by setting a "MAILTO=accountname" option, like this example cron file:

MAILTO=root# run a script every hour01 * * * * root run-parts /etc/cron.hourly#etc.

Any output from the above cron task would be mailed to the root user. As Mike B posted, you can also simply redirect the output elsewhere on the task line using the > operator:

01 * * * * php testscript.php > /var/log/logfile.log

in which case cron does not see it and does not send an email.

The bottom line is that if you leave some echo statements in a PHP script and set it as a cron job, then you will start getting emails from the cron daemon.


Yes they are outputted but to noone in particular (See zombat's answer, it's mailed to the owner of the crontask). You can write the output of your script to a file via:

php myscript.php > /var/log/cronlog.log

(Assuming you're using linux since you said cron and not scheduled task)