2012-12-04 13:31
浏览 341

PHP - 尝试使用error_log()进行日志记录导致500错误

I have an IIS server which is serving PHP via fastcgi. When the error log file is written to by a user other than one in IIS_IUSRS group (The group the IIS User is running under) the file becomes un-writable by IIS and the PHP calls to error_log() causes a 500 error. (At least that's my guess seeing as if I delete the log file, the error dissapears and the log file is re-created).

Is there anyway I can stop the 500 error from happening?

EDIT: To be clear I know I can stop this by stopping logging, logging to event log or different location etc, but that's not what I mean. I mean I just want to prevent the 500 error, I don't care enough that my system can't log that it should break the site when it tries to. That's exactly the worst behaviour it could have. I just want the 500 error to not happen and the site to continue working.

图片转代码服务由CSDN问答提供 功能建议

我有一个通过fastcgi服务PHP的IIS服务器。 当用户写入错误日志文件时 除了IIS_IUSRS组(IIS用户正在运行的组)之外,IIS中的文件变为不可写,并且对 error_log()的PHP调用导致500错误。 (至少那是我的猜测,好像我删除了日志文件,错误消失并重新创建了日志文件)。

无论如何,我可以阻止500错误发生 ?

编辑:要清楚我知道我可以通过停止记录,记录到事件日志或不同位置等来阻止这种情况,但这不是我的意思。 我的意思是我只是想防止500错误,我不在乎我的系统无法记录它应该在尝试时破坏网站。 这正是它可能产生的最糟糕的行为。 我只是想要500错误没有发生,网站继续工作。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

5条回答 默认 最新

  • dszdiavv474681 2013-02-26 11:01

    Since your scheduled task is actually changing the permissions on the error log file, the only viable options I can see are:

    1) Make the scheduled task not write to the error_log. Add the following to the top of the cron job:


    2) Make the scheduled task write to the system log (event viewer in windows) by issuing the following command at the start of your scheduled task (PHP file):

    ini_set('error_log', 'syslog');

    3) If all of the above do not suit you, you can try scheduling the task as the IIS User/Group. This would insure that the permissions are met and error 500 is no longer caused.

    There is no magic fix to this, you can either change the scheduled task so it has the same UID/GID as the PHP process, or you can stop logging in the scheduled_task.

    解决 无用
    打赏 举报

相关推荐 更多相似问题