error_log message is truncated when using print_r
If you check the error INI options in PHP you'll notice there's a log_errors_max_len
option:
Set the maximum length of
log_errors
in bytes. Inerror_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.
Hence, if you want to use error_log
to output these huge messages, make sure you change log_errors_max_len
to a large number (or 0
for unlimited length).
// Append to the start of your script
ini_set('log_errors_max_len', '0');
As scrowler mentions its error_log that's limiting the output.
The error_log will log to syslog by default and in your code, the length of which is limited by the runtime setting log_errors_max_len and which is 1024 by default.
See the following for further details on these functions and settings -
http://php.net/manual/en/function.error-log.php http://php.net/manual/en/errorfunc.configuration.php#ini.log-errors-max-len
What you probably want to do is just call print_r ($bigArray) to have it output directly, or if you want to see something a bit fancier in a browser use
echo '<pre>' . print_r ($bigArray, TRUE) . '</pre>';
If a string in the array contains a null character (byte with value zero), the output will also be truncated at that point. From https://secure.php.net/manual/en/function.error-log.php#refsect1-function.error-log-notes:
Warning
error_log()
is not binary safe.message
will be truncated by null character.
To work around this you could use str_replace
to eliminate null characters:
error_log("big array:" . str_replace("\0", '\\0', print_r($bigArray, true)));
This answer is a bit out of date.
The output from error_log
will still get truncated, even if log_errors_max_len
is set to 0 (for unlimited output).
As per the PHP documentation for log_errors_max_len:
This length is applied to logged errors, displayed errors and also to
$php_errormsg
, but not to explicitly called functions such aserror_log()
.
The only way to get your error_log()
statements to truly output large amounts of information is to specify a custom log file.
error_log("big array:" . print_r($bigArray, true), 3, '/path/to/custom.log');
The second parameter (3) indicates the message type (external log) as per the error_log documentation.