diff --git a/src/Monolog/Handler/StreamHandler.php b/src/Monolog/Handler/StreamHandler.php index ec2519c1..2531d41b 100644 --- a/src/Monolog/Handler/StreamHandler.php +++ b/src/Monolog/Handler/StreamHandler.php @@ -26,9 +26,11 @@ use Monolog\Utils; class StreamHandler extends AbstractProcessingHandler { /** @const int */ - protected const MAX_CHUNK_SIZE = 100 * 1024 * 1024; + protected const MAX_CHUNK_SIZE = 2147483647; + /** @const int 10MB */ + protected const DEFAULT_CHUNK_SIZE = 10 * 1024 * 1024; /** @var int */ - protected $streamChunkSize = self::MAX_CHUNK_SIZE; + protected $streamChunkSize; /** @var resource|null */ protected $stream; /** @var ?string */ @@ -55,13 +57,15 @@ class StreamHandler extends AbstractProcessingHandler if (($phpMemoryLimit = Utils::expandIniShorthandBytes(ini_get('memory_limit'))) !== false) { if ($phpMemoryLimit > 0) { - // use max 10% of allowed memory for the chunk size - $this->streamChunkSize = max((int) ($phpMemoryLimit / 10), 10*1024); + // use max 10% of allowed memory for the chunk size, and at least 100KB + $this->streamChunkSize = min(static::MAX_CHUNK_SIZE, max((int) ($phpMemoryLimit / 10), 100 * 1024)); + } else { + // memory is unlimited, set to the default 10MB + $this->streamChunkSize = static::DEFAULT_CHUNK_SIZE; } - // else memory is unlimited, keep the buffer to the default 100MB } else { - // no memory limit information, use a conservative 10MB - $this->streamChunkSize = 10*10*1024; + // no memory limit information, set to the default 10MB + $this->streamChunkSize = static::DEFAULT_CHUNK_SIZE; } if (is_resource($stream)) {