PHP error_log() 未在 cron 作业中写入磁盘
当将 PHP 脚本作为 cron 作业运行时,错误处理程序可以工作,但 error_log() 函数不会写入磁盘。我将这些行包含在通过 cron 运行的脚本中,以防万一因为 php.ini 值没有被获取,但仍然没有输出到错误日志。
ini_set('display_startup_errors', 0);
ini_set('display_errors', 0);
ini_set('error_log', LOG_FOLDER . 'error_log.txt');
错误处理总体上按预期工作,错误消息出现在我收到的 cron 输出电子邮件中。
作为一种解决方法,我可以通过检查 $_SERVER 来检测脚本是否作为 cron 作业运行,然后使用 fopen() 等写入错误日志。但我希望我可以正确设置它并只使用 error_log( )。
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().
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我刚刚意识到这只是我的错误,LOG_FOLDER 实际上不正确,缺少一个文件夹。 :)
Well I just realized that is was just my mistake and the LOG_FOLDER was actually not correct, there was a folder missing. :)