As a prelude, I know what a HTTP 500 is, and I know how to fix them.
On PHP 5.3, i'm running a production environment with show_errors off. When there are any fatal errors, the user gets a plain white 500 page in response. I'm trying to create a 500 error page just in case there any any errors; just so it is more user friendly.
I used to be able to do
ErrorDocument 500 500.html
It doesn't seem to be working anymore, however - even thought my 404
ErrorDocument 404 404.html
Works fine.
Curious to see solutions regarding this -
Thank you for your time.
Fatal errors don't produce 500 errors in and of themselves, they would return 200 with blank page typically (if no output had been flushed to browser at the point of the error) . Plus this will not help you anyway, as Apache would be no longer involved when PHP is having the error.
Maybe you could register a shutdown function to send 500 header (to get 500 result) and display the content you want to display.
Related
As a prelude, I know what a HTTP 500 is, and I know how to fix them.
On PHP 5.3, i'm running a production environment with show_errors off. When there are any fatal errors, the user gets a plain white 500 page in response. I'm trying to create a 500 error page just in case there any any errors; just so it is more user friendly.
I used to be able to do
ErrorDocument 500 500.html
It doesn't seem to be working anymore, however - even thought my 404
ErrorDocument 404 404.html
Works fine.
Curious to see solutions regarding this -
Thank you for your time.
Fatal errors don't produce 500 errors in and of themselves, they would return 200 with blank page typically (if no output had been flushed to browser at the point of the error) . Plus this will not help you anyway, as Apache would be no longer involved when PHP is having the error.
Maybe you could register a shutdown function to send 500 header (to get 500 result) and display the content you want to display.
I have a php script that uses a third party API that requests information using OAuth and then outputs JSON and then I parse the JSON and foreach JSON tree response insert the data into a database, pretty simple, works great but sometimes the API handshake fails for various reasons and gives me a 500 internal error in the console.
The 500 error seems to be out of my control as it's accessing a third party. Is there a way to force the php script to give a status of 200 OK?
I have tried various combinations of the following and still cannot get it to stop the random 500 error in the console:
header("HTTP/1.1 200 OK");
error_reporting(0);
ini_set('display_errors', 'off');
Is there away?
Regardless I would assume what I am trying to do is bad practice but for this scenario, when the 500 error comes up it completely halts my script!
Server:
Apache 2.4.16,
PHP 5.5.28
What your server replies is entirely in your control. If you get a 500 error it's because your code isn't handling the failure, you probably have an exception being raised somewhere.
Check your error log and figure out where the issue is occurring, then handle the error condition and return what you would like.
I have a J2.5site set up that uses language. Thus the urls look something like this:
https://www.mysite.com/en/
and
https://www.mysite.com/en/my-component/
and
https://www.mysite.com/en/my-component/my-alias
I have also set up a script that emails me whenever a 404 or 500 etc occurs:
Here is the result of one (of hundreds):
500 - Error: 500
Invalid controller: name='index', format=''
Call stack
Function Location
1 JSite->dispatch() /opt/host/apps/joomla/htdocs/index.php:42
2 JError::raiseError() /opt/host/apps/joomla/htdocs/includes/application.php:208
3 JError::raise() /opt/host/apps/joomla/htdocs/libraries/joomla/error/error.php:251
URL:/en/index.php
Notice the request. If I understand correctly, nothing should ever ask for /en/index.php. since by that time, it has already been interpreted by the entry index.php and therefore appends '/en/'
I am not getting any request errors in my apache logs or any other apache errors.
All that is happening is that I am being bombarded with emails stating that something tried to access http://www.mysite.com/en/index.php or https://www.mysite.com/en/my-component/index.php and thus either generated a 404 or 500 error
Is this spider (search engine bot) issues or is it a server misconfiguration?
Thanks
Jacques
I came across an issue today, that my PHP script would send a server error 500 upon finishing (on apache). The code was something like:
//many stuff here that work
echo "It reached here";
exit;
and I was always reaching the point before the exit; command. Doing a google search, I came across this post, which suggested turning on display_errors. I did it and the 500 error went away.
So I wanted to ask, does anyone have an explanation on why this happens? This SO post describes a similar case, but there are no explanations.
As always, thanks in advance
It's pretty likely you get a 500 status code as well, but because PHP echoes something to the browser apache won't jump in and display it's standard status 500 error page.
You would need to verify the actual status code to verify that you won't still get a 500 error.
In case of a fatal error, PHP normally sends a 500 status code. As often the process has failed at that time (hence causing the fatal) and sometime no output is generated since then, the webserver jumps in and gives the user the standard 500-internal-server-error-page.
It appears that the code generated a parse error inside an eval() function in a loop. This kind of error does not break code execution but does produce a 500 error
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
How to make PHP set HTTP status code to 500 automatically in case of any error condition? (including those that cannot be handled by user)
I want to configure Apache to send to the user a 500 response with a custom 500 page when a PHP script raises a fatal error.
What I have now is that it will print the error inline with the page content which is good for development but not for production.
How do I configure Apache to send the user a 500 response with a custom page?
Assuming that you don't only want to send a 500 header (which is easy), but really trigger a 500 error in Apache's system, there seems to be no trivial solution.
According to this question, it is PHP's default behaviour since PHP 5.2.4 if:
a fatal error occurs and
the document body is empty (Gordon found the changelog entry here).
I'm not sure how reliable this behaviour is long term (i.e. when PHP 6 comes up etc.). It's not a much advertised feature.
Other than that, I know of no way of provoking a 500 once the script runs. I asked something similar for 404s once. The answer provided there (redirecting to a predefined URL, and sending a 500 header) may be the best you can get - although that of course won't be logged.
I would say that
ErrorDocument 500 /some/page.php
should do the trick, or just a nice HTML page if you want to be sure that it renders properly even when strange things are preventing PHP pages to render.
In order to trigger the error page you look at this anser : How to return an HTTP 500 code on any error, no matter what
I want to do the same thing but I don't think it is possible with the current version of PHP. First, there is a bug where 500 errors return 200 status. So setting the ErrorDocument 500 in your config file will have no effect. In addition, there appears to be no way to access error information (for custom display and logging) even if it could be redirected.
Triggering an error is easy though. Just add this to a PHP file:
throw new Exception();