0

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.

1
  • 1
    you can add @ in the process , It suppresses error messages. Commented Oct 3, 2013 at 6:26

5 Answers 5

3

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

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks. That's useful. But ini_set('display_errors', 0); did the trick for me here.
@Kaii btw...if I do error_reporting(0); and then try to do error_log('some msg'), will it work?
@nyarlathotep thanks. I got that solution from other stackoverflow question. My points are low so cannot upvote any answer for now :(
@emotionull that's ok, you could still accept it ;) actually before quickly posting my answer I wanted to search for duplicates because I'm sure this was asked before, but on a quick search actually didn't find anything exactly related;) for your error_reporting question, see my updated answer (in a few sseconds
@emotional log_errors = off will just do the tricks with that.
|
2

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.

Comments

1

on the start of that page write

  error_reporting(0);

1 Comment

that will disable any reporting of errors (also in the logfile)
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.

Comments

0

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'.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.