views:

89

answers:

2

I want to manage error message display control,

and I Googled for a while,

and I found that there are several ways to do it.

which method do I have to choose?

The thing I want to do is that

I don't want to PHP
shows up any errors on users display,

on Production Server.

+2  A: 

Use error_reporting()

On production, disable errors by doing:

error_reporting(0);

Report runtime errors on development like this:

error_reporting(E_ERROR | E_WARNING | E_PARSE);

And report all errors like this:

error_reporting(E_ALL);

See the above link for a complete list of report_level constants with detailed descriptions, as well as the manual page:

http://us.php.net/manual/en/function.error-reporting.php

karim79
Are there any diffrencies between "runtime errors" and "all erros" ?
Jonathan itou
This solution seems simple so best for me.
Jonathan itou
+2  A: 

It's best to log all errors to a file:

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 0);
ini_set('log_errors', 1);
ini_set('error_log', '/tmp/php_errors.log');

On unix, you can watch errors using this command:

bash$ tail -f /tmp/php_errors.log

Or you can just open the log file in a text editor.

This setup can be used on a production server as well, you can download the php_errors.log file periodically to see if there are any bugs.

too much php
Do I need to store error log atoutside public_html?
Jonathan itou
Does this solution logs all errors but do not display to user's moniter?
Jonathan itou
"display_errors" function just control wether display errors to moniter?and error_reporting function controls whether logs error?
Jonathan itou
I am confused the diffrencies between them for years.
Jonathan itou
Yes, the php_errors.log file should be outside the public_html folder, or at the very least, somewhere that it can't be downloaded directly.All errors will go into the log file, but users will not see any of them. error_reporting() controls which kinds of errors will be displayed.
too much php
thanks, I understand now.
Jonathan itou