PHP Error Reporting Production vs Development - php

What is best practice when setting error reporting on development and production applications? At the moment I have the following:
// development
error_reporting(E_ALL);
// production
ini_set('display_errors', 0);
ini_set('log_errors', 1);
error_reporting(E_ERROR | E_WARNING | E_PARSE);

Quoting the php-production.ini that should have come bundled with your PHP:
; PHP comes packaged with two INI files. One that is recommended to be used
; in production environments and one that is recommended to be used in
; development environments.
; php.ini-production contains settings which hold security, performance and
; best practices at its core. But please be aware, these settings may break
; compatibility with older or less security conscience applications. We
; recommending using the production ini in production and testing environments.
and further
; display_errors
; Default Value: On
; Development Value: On
; Production Value: Off
; display_startup_errors
; Default Value: Off
; Development Value: On
; Production Value: Off
; error_reporting
; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
; Development Value: E_ALL
; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
; html_errors
; Default Value: On
; Development Value: On
; Production value: On
; log_errors
; Default Value: Off
; Development Value: On
; Production Value: On
Since you asked for best practise, I suggest you go with that.

For the best error logging experience, set error_reporting to -1 (absolutely everything), turn display_errors off, and set a custom error_log.
Then in the terminal, type tail -f /path/to/error_log. Your notices, warnings and errors will now scroll past in real time, without distorting your web page's display.
It's always worth logging everything. In any environment.

Related

Can't get php errors to show when `error_reporting` set to `E_ALL`

I have WAMP with php 5.4.12 and I want to report errors.
My php.ini contains the following:
; Common Values:
; E_ALL & ~E_NOTICE (Show all errors, except for notices and coding standards warnings.)
; E_ALL & ~E_NOTICE | E_STRICT (Show all errors, except for notices)
; E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR (Show only errors)
; E_ALL | E_STRICT (Show all errors, warnings and notices including coding standards.)
; Default Value: E_ALL & ~E_NOTICE
; Development Value: E_ALL | E_STRICT
; Production Value: E_ALL & ~E_DEPRECATED
; http://php.net/error-reporting
error_reporting = E_ALL
but no errors are showing.
What value should error_reporting take and how can I retrieve the reported errors?
I guess display_errors is turned off in your php.ini. Try the following instead (in the php file you are working on).
ini_set('display_errors' , 'On');
error_reporting(E_ALL);
For setting the flag on from php.ini, locate where display_errors is and change the value to On. Post your full php.ini if this does not work.
Can you check whether any error reporting flag in the php script(which will overwrite the php ini flags) in which you are trying to run and also in the .htaccess file. These are the two options which overwrites the php .ini flags.

Include creating HTTP 500

So, I am just about ready to kill a kitten. This is driving me up the wall.
I have a php file I need to include, call it functions.php I have tried the following to include it:-
include './includes/functions.php';
When I did this, I discovered that I get a White Screen of Death. So I went onto more creative solutions;
echo ((include $_SERVER['DOCUMENT_ROOT']. "/includes/functions.php") == 'OK') ? 'GOOD IMPORT' : 'BAD IMPORT';
This was purely to see a visual response to the import. But to no avail, still the White Screen of Emptiness.
The file does exist.
Please, any help is greatly appreciated.
Seems like /includes/functions.php has a syntax error, To stop the "White screen of Death" edit your php.ini
; display_errors
; Default Value: On
; Development Value: On
; Production Value: Off
; display_startup_errors
; Default Value: Off
; Development Value: On
; Production Value: Off
; error_reporting
; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
; Development Value: E_ALL
; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
are values you should probably use. Thats from a stock php.ini file

Enabling PHP ERRORS doesnt apply while making changes in file /etc/php5/cli/php.ini

I cant enable displaying php errors ...At the end I just put defaults and sharing it here
with hope to get some help .. In addition , when I add following piece of code to the php file errors become enabled :
ini_set('display_errors', 1);
ini_set('html_errors', 1);
error_reporting(E_ALL);
Furthermore after adding that code, it still doesnt show syntactic errors
(for example typing "whle" instead of "while")
However, I cant figure out how to make these changes through php.ini :
; display_errors
; Default Value: On
; Development Value: On
; Production Value: On
; display_startup_errors
; Default Value: Off
; Development Value: On
; Production Value: Off
; error_reporting
; Default Value: E_ALL & ~E_NOTICE
; Development Value: E_ALL | E_STRICT
; Production Value: E_ALL & ~E_DEPRECATED
Adding
ini_set('display_errors', 1);
ini_set('html_errors', 1);
error_reporting(E_ALL);
to a file will not work if there are syntax errors in the file as the parser finds the error before the code is run, so the error stops it turning errors on
Editing /etc/php5/cli/php.ini will not work as all you have done is add comments to the file
You would need to uncomment the setting ie remove the ; from in front of it)
display_errors = on
It is also possible that /etc/php5/cli/php.ini is not the right file to edit depending on how your system is configured as Phil has said in comments
<?php phpinfo() ?>
will show you which php file you need to edit and if it is accessed via a webserver eg apache, then you may need to restart your webserver before any changes to that file take effect
you should have
error_reporting = E_ALL
display_errors = On
html_errors = On
in your php.ini file for the php code you are using

XAMPP turn off Strict Standards errors

I am trying to disable Strict Standards from showing up on my screen.
I took a look at my php.ini files and see these lines:
; error_reporting
; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
; Development Value: E_ALL
; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
What do these lines mean and how do I disable the Strict Standards error from showing up?
I also see this line
error_reporting = E_ALL | E_STRICT
I'd change this line
error_reporting = E_ALL | E_STRICT
to the production Production Value
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
You can also change the display_errors settings which will allow you to log errors, but not display them
display_errors = Off

How to disable E_STRICT

I need to turn off E_STRICT. I have error_reporting = E_ALL & ~E_STRICT in my php.ini but it seems to be ignored. I tried this in my code:
ini_set('error_reporting', E_NOTICE);
Nothing!
Please help.
try this.
error_reporting(E_ALL ^ E_STRICT);
This will report all errors except E_STRICT
If you've got your own error handler (search your code for set_error_handler), then the error_reporting config value will be ignored:
It is important to remember that the standard PHP error handler is completely bypassed for the error types specified by error_types unless the callback function returns FALSE. error_reporting() settings will have no effect and your error handler will be called regardless - however you are still able to read the current value of error_reporting and act appropriately. Of particular note is that this value will be 0 if the statement that caused the error was prepended by the # error-control operator.
http://php.net/manual/en/function.set-error-handler.php
Also removing E_STRICT from the error_reporting config could fail, if the error occurs in the same file where error_reporting(...) (or ini_set('error_reporting, ...')) is called.
You mentioned you're using a framework (would be good to know which one) anyway you can add something like this on the very first index.php:
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('display_errors', 'On');
But make sure you're on the first index.php that gets called, meaning the very first in the stack, for certain framework that would save you some pain.
Other thing: most of the frameworks have their own config file to address production software VS. development software and they have their own way of doing things, so I would start from there....have a look at the docs and find out if there's anything there you need to change...it could be a super simple change on a config file most likely.
I was installing CMS Made simple when I ran into that error but here is how I over came it:
1) Open your php.ini file using any of your favorite editors;notepad, notepad++ or dreamweaver.
2) Press ctrl+f to fire up the find Dialog Box.
3) Type E_STRICT and click ok to jump you to the E_STRICT Line, there several E_STRICT Stuff but look for one with this kind of setting;
Common Values:
E_ALL & ~E_NOTICE (Show all errors, except for notices and coding standards warnings.)
E_ALL & ~E_NOTICE | E_STRICT (Show all errors, except for notices)
E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR (Show only errors)
E_ALL | E_STRICT (Show all errors, warnings and notices including coding standards.)
Default Value: E_ALL & ~E_NOTICE
Development Value: E_ALL | E_STRICT
Production Value: E_ALL & ~E_DEPRECATED
http://php.net/error-reporting
error_reporting = E_ALL , here the value with out the ";" is what matters so I just cleared it to:
error_reporting = (delete) and removed the E_ALL, and saved the file, I restarted all the services, and everything worked fine.
Hope that works for you too!.
error_reporting(E_ALL & ~E_STRICT);

Categories