简体   繁体   中英

PHP - attempt to log using error_log() causes 500 error

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.

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:

error_reporting(E_NONE);

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.

Edit the php.ini , and find this line and edit:

error_log = /your/website/path/to/log

And sure to change the display_errors to off:

display_errors = off

Remember to put chmod 777 to the file :). If u wanna to see the file in the browser, can put something like this in the .htaccess file:

<Files /your/site/path/to/log/file.log>
    allow from 10.0.1.1/16
    deny from all
</Files>

PS: Sry, i dnt see the notation are a ISS server... hum, maybe can view more information about the error in the error_log of the ISS (i dont know where is)

I experienced this. Your error_log might be too big for a file. For example, when your error_log reaches 16mb the server will throw an error 500. You may delete your error_log and try if it still throws that error. You may wanna check the error_logs permissions and ownership too.

You want to avoid the error_log function from throwing a 500 Internal Server Error!

Well, if that may be the case, have you tried prepending your call to error_log with an '@'. That could possibly suppress the error. Please try and revert! :)

You could try using error_log() to write your application log in an alternative path:

error_log("Some fancy error to log", 3, "c:\tmp\your-custom-errors.log");

Or you could configure php to log to windows event log (in your php.ini):

error_log = syslog

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM