Php error message length

changing log_errors_max_len has no effect

I’m not experienced in PHP and I had problems logging out big arrays using error_log and print_r . I was told here to change the log_errors_max_len of the php.ini file and I went ahead and did a to see where the php.ini file was loaded from. Then I changed it to log_errors_max_len = 0 but still the output is truncated. I’m also using Laravel. Anybody has any idea why this is not working? (I already restarted apache 🙂

I’m not really sure how big it is since the output is not showing the full array. It is nested with at least 4 levels. See example output here: stackoverflow.com/questions/25621252/…

It crashes the «Manager» class (part of a rest api) and me tailing application log or the apache error log gives no output.

Let the var_dump stay and instead of running it in the browser run the script from (I’m guessing you use linux) linux terminal.

3 Answers 3

The main thing here, is that log_errors_max_len seems pretty useless in this situation. PHP manual states that:

This length is applied to logged errors, displayed errors and also to $php_errormsg, but not to explicitly called functions such as error_log()

The only solution I was able to find so far is to use:

error_log("Long error message. ", 3, CUSTOM_LOG_FILE); 

The second parameter of error_log() allows you to redirect message to a custom file. So, the last parameter should be a path to a custom log file.

Читайте также:  Pdf to html dreamweaver

This way I’m getting full error message and, what might be more important for someone, non ASCII characters are clearly readable there (not sure though, might be my bad, but when I’m logging them with standard log file — I get things like \xd0\xbf ).

Источник

log_errors_max_len = 1024 in php.ini, but php log keeps growing

As the title says, I’ve set the max length for the php error log, but it seems to keep growing much much larger than 1024. I am using the correct php.ini, I’ve restarted apache, etc. The permissions on the php log are 666.

Just out of curiosity, does this directive configure the total length of the file (which makes little sense, as the default value is 1024 bytes), or only the maximum length of one entry / one line ?

There are several php.ini configuration parameters that work together in a somewhat non-intuitive way. On your system, what are the values of log-errors php.net/manual/en/errorfunc.configuration.php#ini.log-errors and error-log php.net/manual/en/errorfunc.configuration.php#ini.error-log ?

3 Answers 3

As is typical for PHP, it is not really obvious from the name of the configuration setting, or even the documentation, but this directive applies to the length of a single log message, not the length of the log file as a whole.

Use logrotate or a similar tool for what you are trying to do.

log_errors_max_len integer

Set the maximum length of log_errors in bytes. In error_log information about the source is added. The default is 1024 and 0 allows to not apply any maximum length at all. This length is applied to logged errors, displayed errors and also to $php_errormsg. When an integer is used, the value is measured in bytes. Shorthand notation, as described in this FAQ, may also be used.

that documentation is clearly incorrect. log_errors is a boolean, so «maximum length of log_errors» is nonsense.

What the manual doesn’t state is that log_errors_max_len refers only to the «body» of the error message. This means that a single line of error will still be greater than the length you set here.

To demonstrate, run this code using log_errors_max_len=0 ( 0 means unlimited) and log_errors=1 :

The bytes sent to error_log will be:

[15-Jul-2015 01:23:45 utc] PHP Notice: Undefined variable: msg1 in C:\index.php on line 5 [15-Jul-2015 01:23:45 utc] PHP Notice: Undefined variable: msg2 in C:\index.php on line 5 ‏ 

Next, test the same code with log_errors_max_len=4 and log_errors=1 . (Remember to restart the server.) error_log will now be:

[15-Jul-2015 01:23:45 utc] PHP Notice: Unde in C:\index.php on line 5 [15-Jul-2015 01:23:45 utc] PHP Notice: Unde in C:\index.php on line 5 ‏ 

(Notice that your error message is prepended with » [15-Jul-2015 01:23:45 utc] PHP Notice: » and appended with » in C:\index.php on line 1 «, resulting in a line longer than what is set by log_errors_max_len .)

This issue occurs not just with error_log , but also with the server output sent to the client. To demonstrate, run the same code above using log_errors_max_len=4 , display_errors=1 , html_errors=0 , error_prepend_string=»PPPP» , and error_append_string=»AAAA» . The output sent to the client is:

PPPP Notice: Unde in C:\index.php on line 5 AAAAPPPP Notice: Unde in C:\index.php on line 5 AAAA 

Now run the same code using log_errors_max_len=4 , display_errors=1 , html_errors=1 , error_prepend_string=»PPPP» , and error_append_string=»AAAA» . ( error_prepend_string and error_append_string apply only to displayed errors, not logged errors.) The output sent to the client is:

PPPP 
Notice: Unde in C:\index.php on line 5
AAAAPPPP
Notice: Unde in C:\index.php on line 5
AAAA

Also note that the above tests would return the same results even if you use ignore_repeated_errors=0 . This shows that «repeated errors» are considered before the error messages are cropped.

(Your results may differ depending on the SAPI used. Above tests are done using php-5.6.7-Win32-VC11-x86 CLI on win 8.1.)

Источник

PHP Error Functions

The error functions are used to deal with error handling and logging.

The error functions allow us to define own error handling rules, and modify the way the errors can be logged.

The logging functions allow us to send messages directly to other machines, emails, or system logs.

The error reporting functions allow us to customize what level and kind of error feedback is given.

Installation

The PHP error functions are part of the PHP core. No installation is required to use these functions.

Runtime Configuration

The behavior of the error functions is affected by settings in php.ini.

Errors and logging configuration options:

Name Default Description Changeable
error_reporting NULL Sets the error reporting level (either an integer or named constants) PHP_INI_ALL
display_errors «1» Specifies whether errors should be printed to the screen, or if they should be hidden from the user.
Note: This feature should never be used on production systems (only to support your development)
PHP_INI_ALL
display_startup_errors «0» Even when display_errors is on, errors that occur during PHP’s startup sequence are not displayed
Note: It is strongly recommended to keep display_startup_errors off, except for debugging
PHP_INI_ALL
log_errors «0» Defines whether script error messages should be logged to the server’s error log or error_log.
Note: It is strongly advised to use error logging instead of error displaying on production web sites
PHP_INI_ALL
log_errors_max_len «1024» Sets the maximum length of log_errors in bytes. The value «0» can be used to not apply any maximum length at all. This length is applied to logged errors, displayed errors, and also to $php_errormsg (available since PHP 4.3) PHP_INI_ALL
ignore_repeated_errors «0» Specifies whether to log repeated error messages. When set to «1» it will not log errors with repeated errors from the same file on the same line (available since PHP 4.3) PHP_INI_ALL
ignore_repeated_source «0» Specifies whether to log repeated error messages. When set to «1» it will not log errors with repeated errors from different files or source lines (available since PHP 4.3) PHP_INI_ALL
report_memleaks «1» If set to «1» (the default), this parameter will show a report of memory leaks detected by the Zend memory manager (available since PHP 4.3) PHP_INI_ALL
track_errors «0» If set to «1», the last error message will always be present in the variable $php_errormsg PHP_INI_ALL
html_errors «1» Turns off HTML tags in error messages PHP_INI_ALL
PHP_INI_SYSTEM in PHP
xmlrpc_errors «0» Turns off normal error reporting and formats errors as XML-RPC error message (available since PHP 4.1) PHP_INI_SYSTEM
xmlrpc_error_number «0» Used as the value of the XML-RPC faultCode element (available since PHP 4.1) PHP_INI_ALL
docref_root «» (available since PHP 4.3) PHP_INI_ALL
docref_ext «» (available since PHP 4.3.2) PHP_INI_ALL
error_prepend_string NULL Specifies a string to output before an error message PHP_INI_ALL
error_append_string NULL Specifies a string to output after an error message PHP_INI_ALL
error_log NULL Specifies 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 PHP_INI_ALL

PHP Error and Logging Functions

Function Description
debug_backtrace() Generates a backtrace
debug_print_backtrace() Prints a backtrace
error_clear_last() Clears the last error
error_get_last() Returns the last error that occurred
error_log() Sends an error message to a log, to a file, or to a mail account
error_reporting() Specifies which errors are reported
restore_error_handler() Restores the previous error handler
restore_exception_handler() Restores the previous exception handler
set_error_handler() Sets a user-defined error handler function
set_exception_handler() Sets a user-defined exception handler function
trigger_error() Creates a user-level error message
user_error() Alias of trigger_error()

PHP Predefined Error and Logging Constants

Value Constant Description
1 E_ERROR Fatal run-time errors. Errors that cannot be recovered from. Execution of the script is halted
2 E_WARNING Run-time warnings (non-fatal errors). Execution of the script is not halted
4 E_PARSE Compile-time parse errors. Parse errors should only be generated by the parser
8 E_NOTICE Run-time notices. The script found something that might be an error, but could also happen when running a script normally
16 E_CORE_ERROR Fatal errors at PHP startup. This is like E_ERROR, except it is generated by the core of PHP
32 E_CORE_WARNING Non-fatal errors at PHP startup. This is like E_WARNING, except it is generated by the core of PHP
64 E_COMPILE_ERROR Fatal compile-time errors. This is like E_ERROR, except it is generated by the Zend Scripting Engine
128 E_COMPILE_WARNING Non-fatal compile-time errors. This is like E_WARNING, except it is generated by the Zend Scripting Engine
256 E_USER_ERROR Fatal user-generated error. This is like E_ERROR, except it is generated in PHP code by using the PHP function trigger_error()
512 E_USER_WARNING Non-fatal user-generated warning. This is like E_WARNING, except it is generated in PHP code by using the PHP function trigger_error()
1024 E_USER_NOTICE User-generated notice. This is like E_NOTICE, except it is generated in PHP code by using the PHP function trigger_error()
2048 E_STRICT Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code (Since PHP 5 but not included in E_ALL until PHP 5.4)
4096 E_RECOVERABLE_ERROR Catchable fatal error. 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 (Since PHP 5.2)
8192 E_DEPRECATED Run-time notices. Enable this to receive warnings about code that will not work in future versions (Since PHP 5.3)
16384 E_USER_DEPRECATED User-generated warning message. This is like E_DEPRECATED, except it is generated in PHP code by using the PHP function trigger_error() (Since PHP 5.3)
32767 E_ALL Enable all PHP errors and warnings (except E_STRICT in versions < 5.4)

Источник

Оцените статью