3

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.

2
  • Besides the IIS User (which PHP runs under), which user does write to the error_log? It seems to me that multiple roles are trying to write to that file. What other applications/users are writing to the error_log file? Commented Feb 24, 2013 at 0:37
  • There is a cron job (or scheduled task or whatever windows calls these things) which runs PHP which also logs. I know that this is the root cause, and as I've tried to emphasise, I don't need a fix for this individual case... I'd like to know how to prevent error_log from being able to issue a 500 error, bringing down the site for the user. It's a logging function, so it being unable to write to a log file, should not cause a user to be unable to use the site. Commented Feb 25, 2013 at 8:10

5 Answers 5

2

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.

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

Comments

1

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)

1 Comment

Thanks, but you completely missed the point. I know how to configure php to log, I want to prevent the 500 error if it is unable to log.
1

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.

2 Comments

Wow - you super didn't read the whole question ;) Thanks - but I know how to "fix" it so that it won't happen in the individual case. I want to know how to prevent error_log from being able to case a 500 error. It's a logging function, it should not be able to take down the entire site if it fails.
@Kapitanluffy that about the 16MB log size ... you said it like it's an absolute rule, if it happened to you it might be able to be changed somewhere, because my log is 17MB right now and I'm having no problems at all
1

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! :)

Comments

0

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

4 Comments

Thanks, but please see my edit. I know how to do all of that, but that's not what I was intending on asking...
Then it sounds like you need to add the user triggering the error_log to the IIS group.
Still missing the point. I don't want error_log() to cause a 500 error under any circumstances. I don't want to have to account for all circumstances that might prevent it logging. It's poorly designed if logging causes the site to break. It's not an error that the users care about.
Have you tried with @error_log()? If it does not work, maybe you could write your own error handler? php.net/manual/es/function.set-error-handler.php

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.