While working on CLI, all PHP log files are written to the standard output(STDOUT) standard error(STDERR). When running as a server module, PHP writes all logs to the SAPI logger. For Apache HTTP Server it is the error log file defined in the server configuration file.
In PHP, we can change and enhance error reporting to suit our needs. We can customize to what level and kind of error feedback is given, ranging from simple notices to customized functions returned during errors. We can modify the error logging behavior in PHP including the method by which error log is saved or handled. We can selectively log and monitor the important parts of our applications and websites.
http://php.net/manual/en/book.errorfunc.php
For the convenience, we will break up error reporting in PHP into following three sections.
1) Predefined Constants
2) Bitwise Operators
3) Configuration Options
1) Predefined Constants
Predefined Constants inform PHP of which errors, warnings and notices we would like it to take action for. These constants are set as values for configuration options directives in php.ini or other PHP configuration files. We may use these constant names in PHP configuration file(example: php.ini) but not outside of PHP(example: httpd.conf), where we should use bitmask values instead.
http://php.net/manual/en/errorfunc.constants.php
E_ERROR
BITMASK VALUE: 1
Fatal run-time errors. These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted.
E_WARNING
BITMASK VALUE: 2
Run-time warnings (non-fatal errors). Execution of the script is not halted.
E_PARSE
BITMASK VALUE: 4
Compile-time parse errors. Parse errors should only be generated by the parser.
E_NOTICE
BITMASK VALUE: 8
Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script.
E_CORE_ERROR
BITMASK VALUE: 16
Fatal errors that occur during PHP‘s initial startup. This is like an E_ERROR, except it is generated by the core of PHP.
E_CORE_WARNING
BITMASK VALUE: 32
Warnings (non-fatal errors) that occur during PHP‘s initial startup. This is like an E_WARNING, except it is generated by the core of PHP.
E_COMPILE_ERROR
BITMASK VALUE: 64
Fatal compile-time errors. This is like an E_ERROR, except it is generated by the Zend Scripting Engine.
E_COMPILE_WARNING
BITMASK VALUE: 128
Compile-time warnings (non-fatal errors). This is like an E_WARNING, except it is generated by the Zend Scripting Engine.
E_USER_ERROR
BITMASK VALUE: 256
User-generated error message. This is like an E_ERROR, except it is generated in PHP code by using the PHP function trigger_error().
E_USER_WARNING
BITMASK VALUE: 512
User-generated warning message. This is like an E_WARNING, except it is generated in PHP code by using the PHP function trigger_error().
E_USER_NOTICE
BITMASK VALUE: 1024
User-generated notice message. This is like an E_NOTICE, except it is generated in PHP code by using the PHP function trigger_error().
E_STRICT
BITMASK VALUE: 2048
Enable to have PHP suggest changes to our code which will ensure the best interoperability and forward compatibility of our code.
NOTE: Since PHP v5. Not included in E_ALL until PHP v5.4.0.
E_RECOVERABLE_ERROR
BITMASK VALUE: 4096
Catchable fatal error. It indicates that a probably dangerous error occurred, but did not leave the Engine in an unstable state. If the error is not caught by a user defined handle, the application aborts as it was an E_ERROR.
E_DEPRECATED
BITMASK VALUE: 8192
Run-time notices. Enable this to receive warnings about code that will not work in future versions.
E_USER_DEPRECATED
BITMASK VALUE: 16384
User-generated warning message. This is like an E_DEPRECATED, except it is generated in PHP code by using the PHP function trigger_error().
E_ALL
BITMASK VALUE: 32767
All errors and warnings supported.
2) Bitwise Operators
Bitwise operators allow evaluation and manipulation of specific bits within an integer. The predefined constants described above can be used to build up a bitmask that specifies which errors to report. We can use the bitwise operators to combine these values or mask out certain types of errors.
http://php.net/manual/en/language.operators.bitwise.php
NOTE: While setting Bitmasks, we should mind the Operator precedence, which decides what the result of an expression will be. More about Operator precedence is available at http://php.net/manual/en/language.operators.precedence.php
NOTE: Only the Bitwise operators understood within php.ini are given here. For a complete list of Bitwise operators, goto http://php.net/manual/en/language.operators.bitwise.php
Bitwise Operators
Operator Meaning
~ Not
& And
^ Xor
| Or
Bitmask Examples
Bitmask Meaning
~ $a Bits that are set in $a are not set, and vice versa.
$a & $b Bits that are set in both $a and $b are set.
$a ^ $b Bits that are set in $a or $b but not both are set.
$a | $b Bits that are set in either $a or $b are set.
Example as in php.ini
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
This reports all errors except those returned by E_DEPRECATED and E_STRICT.
3) Configuration Options
These are the PHP directives that control the error logging in PHP. We may use the Predefined Constants described above in conjuction with Bitwise Operators to customize our values.
display_errors
Directive mode: PHP_INI_ALL
Development Value: On
Production Value: Off
This determines whether errors should be printed to the screen as part of the output or if they should be hidden from the user. Here the value STDERR sends the errors to Standard Error instead of Standard Output.
http://php.net/manual/en/errorfunc.configuration.php#ini.display-errors
display_startup_errors
Directive mode: PHP_INI_ALL
Development Value: On
Production Value: Off
Errors that occur during PHP‘s startup sequence are not displayed even if display_errors option is turned on. This option determines whether those errors should be displayed.
http://php.net/manual/en/errorfunc.configuration.php#ini.display-startup-errors
error_reporting
Directive mode: PHP_INI_ALL
Development Value: E_ALL
Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
This sets the error reporting level. The parameter can be predefined constants expressed with/without Bitwise Operators or an integer representing a Predefined Constant or Bitmask.
http://php.net/manual/en/errorfunc.configuration.php#ini.error-reporting
docref_ext
Directive mode: PHP_INI_ALL
This value has not been set.
Defines the file extension of our manual file. The value must always start with a dot(.). For example .html.
http://php.net/manual/en/errorfunc.configuration.php#ini.docref-ext
docref_root
Directive mode: PHP_INI_ALL
This value has not been set.
The error format contains a reference to the manual page describing the error or function causing the error. We can download the manual in our language and set this ini directive to the URL of our local copy. If our local copy of the manual is in the subdirectory phpmanual, then we can use the value /phpmanual/. It is also possible to use external reference like http://manual/en/.
http://php.net/manual/en/errorfunc.configuration.php#ini.docref-root
error_append_string
Directive mode: PHP_INI_ALL
This value has not been set.
Defines the string which should be displayed immediately after the error message is displayed in the browser.
http://php.net/manual/en/errorfunc.configuration.php#ini.error-append-string
error_log
Directive mode: PHP_INI_ALL
This value has not been set.
Defines the name of the file where script errors should be logged. The file should be writable by the web server’s user. If the special value syslog is used, the errors are sent to the system logger instead. On Unix, this means syslog(3). If this directive is not set, errors are sent to the SAPI error logger. For Apache HTTP Server it is the error log file defined in the server configuration file, while it is the STDERR in CLI.
http://php.net/manual/en/errorfunc.configuration.php#ini.error-log
error_prepend_string
Directive mode: PHP_INI_ALL
This value has not been set.
Defines the string which should be displayed immediately before the error message is displayed in the browser.
http://php.net/manual/en/errorfunc.configuration.php#ini.error-prepend-string
html_errors
Directive mode: PHP_INI_ALL
Development Value: On
Production value: On
Decides whether or not to have HTML tags in error messages. HTML errors produces clickable messages that direct the user to a page describing the error or function in causing the error. These references are affected by options docref_root and docref_ext.
http://php.net/manual/en/errorfunc.configuration.php#ini.html-errors
ignore_repeated_errors
Directive mode: PHP_INI_ALL
Development Value: Off
Production Value: Off
This decides whether or not to log multiple occurrences of the same errors, when they come from the same line of the same file.
http://php.net/manual/en/errorfunc.configuration.php#ini.ignore-repeated-errors
ignore_repeated_source
Directive mode: PHP_INI_ALL
Development Value: Off
Production Value: Off
This decides whether or not to log multiple occurrences of the same errors, when they come from different lines in different files.
http://php.net/manual/en/errorfunc.configuration.php#ini.ignore-repeated-source
log_errors
Directive mode: PHP_INI_ALL
Development Value: On
Production Value: On
Decides whether script error messages should be logged to the server’s error log or error log file defined by PHP.
http://php.net/manual/en/errorfunc.configuration.php#ini.log-errors
log_errors_max_len
Directive mode: PHP_INI_ALL
Development Value: 1024
Production Value: 1024
This sets the maximum length of log_errors in bytes. In error log file, information about the source is added. A value of 0 does not set a limit on maximum length. This length is applied to logged errors, displayed errors and also to $php_errormsg.
http://php.net/manual/en/errorfunc.configuration.php#ini.log-errors-max-len
report_memleaks
Directive mode: PHP_INI_ALL
Development Value: On
Production Value: On
Decides whether or not to show a report of memory leaks detected by the Zend Memory Manager. On POSIX platforms this report will be send to STDERR, which can be later viewed by a debugging tool. This parameter only has effect in a debug build, and if error_reporting includes E_WARNING in the allowed list.
http://php.net/manual/en/errorfunc.configuration.php#ini.report-memleaks
report_zend_debug
Directive mode: PHP_INI_ALL
Development Value: On
Production Value: On
Prints out descriptive bug messages in case of error in PHP development. This has no effect unless we have compiled PHP without the –enable-debug option. This option won’t affect our error logging unless we are developing PHP or it’s extensions.
http://php.net/manual/en/ini.list.php
track_errors
Directive mode: PHP_INI_ALL
Development Value: On
Production Value: Off
Decides whether or not to have the last error message be present in the variable $php_errormsg.
http://php.net/manual/en/errorfunc.configuration.php#ini.track-errors
xmlrpc_errors
Directive mode: PHP_INI_SYSTEM
Development Value: 0
Production value: 0
Decides whether or not to turn off normal error reporting and instead use XML-RPC format.
http://php.net/manual/en/errorfunc.configuration.php#ini.xmlrpc-errors
xmlrpc_error_number
Directive mode: PHP_INI_ALL
Development Value: 0
Production value: 0
Defines the XML-RPC fault code to use when xmlrpc_errors is enabled.
http://php.net/manual/en/errorfunc.configuration.php#ini.xmlrpc-error-number
You may go back to the following section.
Installing PHP