Skip to content

Commit

Permalink
Avoid OOM errors because of large log files
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk authored Oct 4, 2024
1 parent cbaa556 commit 2129829
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion HealthCheck/Tools/class-health-check-debug-log-viewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ private function read_debug_log() {
return '';
}

$debug_log = @file_get_contents( $logfile );
if ( ! is_readable( $logfile ) ) {
return sprintf(
// translators: %s: The path to the debug log file.
__( 'The debug log file found at `%s`, could not be read.', 'health-check' ),
$logfile
);
}

// Only read the last 200k of the log file to avoid Oout of memory errors.
$debug_log = file_get_contents( $logfile, null, null, max( 0, filesize( $logfile ) - 200000 ) );

if ( false === $debug_log ) {
return sprintf(
Expand Down

0 comments on commit 2129829

Please sign in to comment.