My PHP web-app sometimes returns this Fatal error on Line XXX
due to reasons like extremely-slow-connection speed. Although, this occurs rarely, like 1 in 1000 times, I want to avoid such output on the browser. I am doing error logging on server side for some functions. So, I don't want to completely disable error reporting. Just that I don't want to display it to the end user.
5 回答
Various Examples on turning off error_reporting..
<?php
// Turn off all error reporting
error_reporting(0);
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
// Report all PHP errors
error_reporting(-1);
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
?>
note : You can put or include()
it in any file you dont want to explicit errors. Or if you want to totally off it. Go with tweaks in php.ini file.
Lines to find in your php.ini to tweaks and off error_reporting.
ini_set('display_errors', 'On'); //change to Off
error_reporting(E_ALL); // change to 0
FOR FURTHER INFO :: PHP.NET
To disable any error display to the user of your page, set
display_errors = Off
in your php.ini (this is the recommended setting for production websites anyway!) or
ini_set('display_errors', 0);
in your php.
This display_errors
setting only affects the output on the webpage; it will not affect a possibly configured logfile; there the messages still would be logged.
See the php documentation on configuring error reporting: http://php.net/manual/en/errorfunc.configuration.php
Note: The error_reporting
setting mentioned by other users here, will, to my knowledge, affect all kinds of error reports (i.e. also what is reported to a possibly configured log file). If you set error_reporting
to 0, you won't get any log entries as well. If you want to log something to the log file but not show it to the user, the display_errors
setting is the way to go.
on the start of that page write
error_reporting(0);
To avoid issues like this you can set the max_execution_time=1024M to avoid slow speed data generation and to hide errors is must likely error_reporting=0 on the php.ini file.
Or simply:
PHP Code
ini_set('max_execution_time',1024M);
error_reporting(0);
PHP Ini Settings
max_execution_time=1024M
error_reporting=0
Hope it helps.
error_reporting(0); only works if you are not using set_error_handler('my_function'). If this is your case, you have suppress the error message in 'my_function'.