@@ -1843,14 +1843,39 @@ protected function has_fatal_error() {
18431843 $ fatal_error = null ;
18441844
18451845 $ last_error = error_get_last ();
1846- if ( $ last_error && in_array ( $ last_error ['type ' ], [1 ,2 ,4 ,256 ] ) ) {
1847- $ fatal_error = "PHP Fatal error: {$ last_error ['message ' ]} in {$ last_error ['file ' ]} on line {$ last_error ['line ' ]}" ;
1848- } elseif ( file_exists ( WP_CONTENT_DIR . '/debug.log ' ) ) {
1849- $ lines = array_reverse ( file ( WP_CONTENT_DIR . '/debug.log ' , FILE_IGNORE_NEW_LINES ) );
1850- foreach ( $ lines as $ line ) {
1851- if ( strpos ( $ line , 'PHP Fatal error ' ) !== false ) {
1852- $ fatal_error = trim ( $ line );
1853- break ;
1846+ if ( $ last_error && in_array ( $ last_error ['type ' ], [ E_ERROR , E_PARSE , E_COMPILE_ERROR , E_USER_ERROR ] ) ) {
1847+ $ fatal_error = "PHP Fatal error: {$ last_error ['message ' ]} in {$ last_error ['file ' ]} on line {$ last_error ['line ' ]}" ;
1848+ } else {
1849+ $ log_file = WP_CONTENT_DIR . '/debug.log ' ;
1850+ if ( file_exists ( $ log_file ) && is_readable ( $ log_file ) ) {
1851+ $ handle = fopen ( $ log_file , 'r ' );
1852+ if ( $ handle ) {
1853+ $ pos = -2 ;
1854+ $ current_line = '' ;
1855+ while ( $ pos > -filesize ( $ log_file ) ) {
1856+ fseek ( $ handle , $ pos , SEEK_END );
1857+ $ char = fgetc ( $ handle );
1858+ if ( $ char === "\n" ) {
1859+ if ( $ current_line !== '' ) {
1860+ $ line = strrev ( $ current_line );
1861+ if ( strpos ( $ line , 'PHP Fatal error ' ) !== false ) {
1862+ $ fatal_error = trim ( $ line );
1863+ break ;
1864+ }
1865+ $ current_line = '' ;
1866+ }
1867+ } else {
1868+ $ current_line .= $ char ;
1869+ }
1870+ $ pos --;
1871+ }
1872+ if ( $ current_line !== '' && $ fatal_error === null ) {
1873+ $ line = strrev ( $ current_line );
1874+ if ( strpos ( $ line , 'PHP Fatal error ' ) !== false ) {
1875+ $ fatal_error = trim ( $ line );
1876+ }
1877+ }
1878+ fclose ( $ handle );
18541879 }
18551880 }
18561881 }
0 commit comments