1

When running PHP scripts as cron jobs, the error handler works but the error_log() function doesn't write to disk. I included these lines in the script run through cron in case it was because the php.ini values weren't getting picked up, but still no output to the error log.

ini_set('display_startup_errors', 0);
ini_set('display_errors', 0);
ini_set('error_log', LOG_FOLDER . 'error_log.txt'); 

Error handling in general is working as expected, and the error messages appear in the cron output email that I get.

As a workaround I could detect that the script is running as a cron job by checking $_SERVER, and then writing to the error log using fopen(), etc. But I was hoping I could get it set up right and just use error_log().

3
  • Are you sure LOG_FOLDER is correctly defined? What does echo LOG_FOLDER . 'error_log.txt' produce? Commented May 20, 2010 at 14:49
  • You could just redirect the output of the cron. In crontab: php yourcommand.php &> /path/to/error_log.txt Commented May 20, 2010 at 14:54
  • I have printed out the LOG_FOLDER and it's echoing the correct path, yes. Commented May 20, 2010 at 15:31

1 Answer 1

1

Well I just realized that is was just my mistake and the LOG_FOLDER was actually not correct, there was a folder missing. :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.