phploggingcron

Running a PHP script via cron, how can I log any output?


I have a PHP script which I have been testing, and seems to run fine when I call it from the command line.

I now want to automate it via cron, how can I get the outputs I have put into the file as checkpoints into a log file?

e.g. I have some simple echo commands in the script and I'd like the output to appear inside an existing log file (so that it get's automatically rotated etc).


Solution

  • Cron command to run:

    /path/to/php -f /path/to/script.php >> /path/to/logfile.txt &2>1
    

    Note that all paths must be absolute and in order to see PHP errors they have to be enabled (i.e display_errors=on).