Php registration error - error_reporting (0), not having the desired effect

I have a pretty simple page that retrieves the url and parses some data.

I created some error handling on my page in case the answer is a 404 error.

However, I cannot get PHP to ignore the following errors.

Warning: file_get_contents (http://url-to-retrieve.com/123.html) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP / 1.1 404 Not Found in /var/www/html/maickl/procs/get.php on line 84

Notice: Undefined offset: 0 in /var/www/html/maickl/procs/get.php on line 91

I start the page with

error_reporting (0)

Any suggestions as to why this is happening, why these errors are not suppressed (it seems only on this page), and what can I do about it?

+3
source share
3 answers

Using error_reporting(0);shoud to disable the error report, which means that you should not receive this error - are you sure that it has not been reactivated somewhere?


But in reality, you most likely do not want to change error_reporting, but disable display_errors, which can be done with some code like this:

ini_set('display_errors', 'Off');

Wherein:

  • errors / warnings will not be displayed on your website, which is pleasant for end users (technical errors should never be displayed)
  • but error_reportingnot disabled, which means that errors can / will be written to the system - see log_errorsand error_log.
+5
source

, , error_reporting() .

+5

Disabling error reporting is one way to do this, but I would suggest just fixing the error or adding the appropriate error handling.

try {
     //try to do the following
     $content = file_get_contents('file/to/try.txt');
} catch (Exception $e) {
     //do this in case of an error
     die($e->getMessage());
}
+3
source

Source: https://habr.com/ru/post/1735094/


All Articles