views:

83

answers:

2

Hi, my boss says "when I try to serf the website I get a server error... after a reload I get every thing back to normal". I think that he gets 500 error. how can I log it? I want to know when and where it happens. any ideas?

+6  A: 

500 errors are logged in your web server's error log, for Apache that is usually error.log. You should be able to find all errors there, including the requesting IP and the exact message.

If you don't have access to the error logs, if you have Apache, you can try this in a .htaccess file:

ErrorDocument 500 /my_error_handler.php

my_error_handler.php would then send out an E-Mail to you or something. This won't give you the exact error message, though.

Pekka
Assuming he's using Apache
Andy E
True that. -----
Pekka
A: 

According to the comments, this is not the case on Apache, but is the case on IIS. If you think the error is related to your PHP code then it's possible this is what's causing the status 500 error.

There are several ini directives you can set to deal with server errors. I recommend having error logging switched on. See the following site for each ini directive:

http://www.addedbytes.com/drafts/php-ini-guide/php-ini-guide-error-handling-and-logging/

Add/Change/Uncomment the ones you want in your php.ini file.

With logging switched on, the following php code generates the following error string in the error log file:

<?php this_is_undefined(); ?>

error log - [05-Jan-2010 12:44:29] PHP Fatal error: Call to undefined function this_is_undefined() in D:\websites\leaguers.co.uk\test.php on line 1

Andy E
This won't catch 500 errors (which are triggered by the web server, not by PHP).
Pekka
A fatal error in PHP will trigger a 500: http://www.leaguers.co.uk/test.php contains `<? undefined_function(); ?>` and it throws a 500 just fine.
Andy E
For which the PHP log file shows: `[05-Jan-2010 12:44:29] PHP Fatal error: Call to undefined function undefined_function() in D:\websites\leaguers.co.uk\test.php on line 1`
Andy E
I think this is a Windows Server specialty. It doesn't on any Linux based box I've ever seen. http://www.webdigi.co.uk/blog/2009/php-on-windows-server-2008-500-internal-server-error-on-iis/comment-page-1/
Pekka
OK. But that site does say `The server logs do not say a lot except for the fact that the php file is causing an error.`, in which case using the php error logs would be a suitable solution :)
Andy E