seek( PHP_INT_MAX ); $last_line = $file->key(); $iterator = new LimitIterator( $file, $last_line > 3500 ? $last_line - 3500 : 0, $last_line ); $lines = iterator_to_array( $iterator ); $previous_line = null; foreach ( $lines as $line ) { // Parse the date $date = ''; try { $dateArr = []; preg_match( '~^\[(.*?)\]~', $line, $dateArr ); if ( isset( $dateArr[0] ) ) { $line = str_replace( $dateArr[0], '', $line ); $line = trim( $line ); $date = new DateTime( $dateArr[1] ); $date = get_date_from_gmt( $date->format('Y-m-d H:i:s'), 'Y-m-d H:i:s' ); } else { continue; } } catch ( Exception $e ) { continue; } // Parse the error $type = ''; if ( preg_match( '/PHP Fatal error/', $line ) ) { $line = trim( str_replace( 'PHP Fatal error:', '', $line ) ); $type = 'fatal'; } else if ( preg_match( '/PHP Warning/', $line ) ) { $line = trim( str_replace( 'PHP Warning:', '', $line ) ); $type = 'warning'; } else if ( preg_match( '/PHP Notice/', $line ) ) { $line = trim( str_replace( 'PHP Notice:', '', $line ) ); $type = 'notice'; } else if ( preg_match( '/PHP Parse error/', $line ) ) { $line = trim( str_replace( 'PHP Parse error:', '', $line ) ); $type = 'parse'; } else if ( preg_match( '/PHP Exception/', $line ) ) { $line = trim( str_replace( 'PHP Exception:', '', $line ) ); $type = 'exception'; } else { continue; } // Skip the error if is the same as before. if ( $line !== $previous_line ) { array_push( $output_lines, array( 'date' => $date, 'type' => $type, 'content' => $line ) ); $previous_line = $line; } } } catch ( OutOfBoundsException $e ) { error_log( $e->getMessage() ); return array(); } } return $output_lines; // else { // $output_lines = array_reverse( $output_lines ); // $html = ''; // $previous = ''; // foreach ( $output_lines as $line ) { // // Let's avoid similar errors, since it's not useful. We should also make this better // // and not only theck this depending on tie. // if ( preg_replace( '/\[.*\] PHP/', '', $previous ) !== preg_replace( '/\[.*\] PHP/', '', $line ) ) { // $html .= $line; // $previous = $line; // } // } // return $html; // } } } // Asked by WP Security Team to remove this. // if ( MeowCommon_Helpers::is_rest() ) { // ini_set( 'display_errors', 0 ); // } } ?>