I have a page written in PHP. I do not have access to the server. I'd like to make so that instead of showing an error message when PHP encounters an error, it gives a 500.
PHP 5.2 by default sends HTTP 500 in case of fatal error, if display_errors is off.
If the hosting is with older PHP, you have to register your own error handler and possibly exception handler and redirect the user to your 500 error page. Try setting the display_errors and error_reporting variables in your PHP script as #Umang suggested.
you can create your own error handler and use it to send 503 status code to the client.
Related
In /var/log/apache2/error.log I able to trace http 500 error, Only I able to log error when I hit url from browser but when I call api either via ajax call or by postman, then any syntax error(500 error) not logged in apache2/error.log . Please tell me how can I log this one as well. Thx! in advance.
If you're getting an error and there's nothing wrong with your Apache, then there's probably an issue with your PHP. Look in your PHP error log for an error. If PHP is not logging errors then you need to change the php.ini file so that log_errors is 1 and error_log is the file name you want errors to be logged to. (I recommend "error_log". This will log all errors to the file error_log in the same directory as the file creating the error.)
I am getting Error i tried to find but did not get why getting Error.While its working fine on my localhost but not working on live server.
http://wellnessvisit.com/vascular-new/assets/global/plugins/jquery-file-upload/server/php/
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster#wellnessvisit.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Normally production servers are configured to hide all error information.
You can add these two lines in your main php file to see if there's a way to get the error information (temporarily, be sure to delete them after you're done debugging):
error_reporting(E_ALL);
ini_set('display_errors', 'On');
You can also check if there's an error_log file in the same folder as your PHP script, many servers log the errors to a file.
If no luck, with the previous lines, it might be a syntax error so the parsing is not completed.
In Symfony2 I'm getting a custom twig error message when an error 500 is thrown:
Oops! An Error Occurred
The server returned a "500 Internal Server Error".
Something is broken. Please e-mail us at [email] and let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.
I just want default php errors instead.
If possible, only in dev.
display_errors is on in php.ini and looking at phpinfo()
I tried to add the following lines to app/config/config.yml
services:
twig.exception_listener:
class: DateTime
#dummy to prevent twig from handling http error pages
The result is that I get a blank page instead of the php error page with error and lines for debugging.
Thanks,
Boris
That's because Symfony2 wraps the whole process from the Request to the Response. Native PHP errors occur when not caught by Symfony2.
And native PHP errors can't be thrown if it's not a native PHP error. You'd get a real 500 error code page only if Symfony2 core would fail in rendering the response.
I don't see any other explanations. You can find more information about the error process by flowing this link.
This links explains why you do have a blank page : 500 error code exception is thrown but Twig is not listening this event anymore (as you disabled it). So nothing happens.
My server is setup with Nginx + PHP + FastCGI. Whenever PHP throws a Fatal error, it gets logged inside of nginx/error.log, but the server reports HTTP Error 500 back to the browser instead of displaying the PHP Fatal error to the browser as is desired and typical in other setups. I've been searching for how to resolve this and keep coming up short. Anyone have anything helpful about this? Much appreciated!
Found it!
As of PHP 5.2.4, the default is now to cause a 500 error, because the alternative is an empty page.
Other discussions suggest that this behavior can not be changed for the "PHP Fatal" error type, which don't flow through the normal error handler routines and can not be caught or stopped.
You probably have php_errors off (or the displaying of them) in your php loader script... Try checking your php.ini settings...
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?
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.
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