diff --git a/includes/OrderedStreamingForkController.php b/includes/OrderedStreamingForkController.php index ff29cb510dc..11abc81c1ff 100644 --- a/includes/OrderedStreamingForkController.php +++ b/includes/OrderedStreamingForkController.php @@ -134,9 +134,12 @@ class OrderedStreamingForkController extends ForkController { */ protected function consumeNoFork() { while ( !feof( $this->input ) ) { - $line = trim( fgets( $this->input ) ); - if ( $line ) { - $result = call_user_func( $this->workCallback, $line ); + $data = fgets( $this->input ); + if ( $data[ strlen( $data ) - 1 ] == "\n" ) { + $data = substr( $data, 0, -1 ); + } + if ( strlen( $data ) !== 0 ) { + $result = call_user_func( $this->workCallback, $data ); fwrite( $this->output, "$result\n" ); } } @@ -160,8 +163,12 @@ class OrderedStreamingForkController extends ForkController { $this->updateAvailableSockets( $sockets, $used, $sockets ? 0 : 5 ); } while ( !$sockets ); } - $data = trim( $data ); - if ( !$data ) { + // Strip the trailing \n. The last line of a file might not have a trailing + // \n though + if ( $data[ strlen( $data ) - 1 ] == "\n" ) { + $data = substr( $data, 0, -1 ); + } + if ( strlen( $data ) === 0 ) { continue; } $socket = array_pop( $sockets );