I didnt know wether to post this in here, apache or mysql category because its a bit of a mixture. However I want my server to return a 500 error code when mysql has “too many connections”.
Currently, if my server gets overloaded for whatever reason all the pages will get a 200 OK response if all the mysql connections are used up. And if Google are crawling my site at the same time, its not good news!
thanks a lot for the reply, however that didnt seem to work?
I got the following error on the frontend;
Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user ‘nobody’@‘localhost’ (using password: NO) in /XXXX/XXXXX/public_html/includes/XXXX.inc.php on line 19
you may be took this code too literally
this was an example. not to copy and paste but to understand and implement.
mysqli_connect() usually require not empty comment but some parameters, which obviously unknown to Anthony…
also you must turn displaying errors off on your public server,
by using
ini_set(“display_errors”, 0);
ini_set(“log_errors”, 1);
if ( $productId == "" ) {
header("HTTP/1.1 404 Not Found");
include "404.php";
exit;
}
This produces a 404 if there is no product id found. What can I change this too so that it does the 404 thing, but also produces a 500 if mysql cant connect.?
These are the headers I use and what I use them for.
HTTP/1.0 200 Ok
This is both Apache and PHP’s default header.
HTTP/1.0 207 Updated
This response code is used exclusively to reply to the Javascript side of my framework. The javascript code infers that PHP has completed its share of the action when it sees this code. The browser does not cache any response with this header (which is why it is used instead of simply 200 ok.
HTTP/1.0 209 Partial Content
This is used when PHP is sending an XML or JSON file with an HTML snippet that javascript needs to append into the page. Again, this code isn’t normally cachable.
HTTP/1.0 320 Reload
Another header sent only in response to an Ajax request, when my Javascript code reads this header it finishes whatever it’s doing and then reloads the entire page including itself. This header is not part of the standard so browsers will treat it as if it was code 300, which is the redirect class of codes.
HTTP/1.0 400 Bad Request
The client side code sent something the server didn’t expect. I raise this error when forms don’t validate and sending the error page back. Again, like most error codes caching is avoided.
HTTP/1.0 401 Unauthorized
User has no permission to perform the action requested.
HTTP/1.0 403 Forbidden
As above, but generally used in response to file access attempts.
HTTP/1.0 404 Not Found
Anyone not use this yet
HTTP/1.0 500 Internal Server Error
I send this header with any PHP exception that escapes since I consider the script part of the server.
HTTP/1.0 520 Programmer Debug Output
My debug functions send this header. Again, not part of the standard, will be treated as a vanilla 500.