X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FOrderedStreamingForkController.php;h=5424b13285665203c675cb27712e3315186a9614;hb=d60849c5de08db4cf027325f17f1a3705e106b5d;hp=ff29cb510dc10e2a6dd8a5344f065840841e4c20;hpb=23f0ce46d46d06e4aa71b9bfe6d47bc5aaa63e68;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/OrderedStreamingForkController.php b/includes/OrderedStreamingForkController.php index ff29cb510d..5424b13285 100644 --- a/includes/OrderedStreamingForkController.php +++ b/includes/OrderedStreamingForkController.php @@ -134,11 +134,17 @@ 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 ); - fwrite( $this->output, "$result\n" ); + $data = fgets( $this->input ); + if ( substr( $data, -1 ) === "\n" ) { + // Strip any final new line used to delimit lines of input. + // The last line of input might not have it, though. + $data = substr( $data, 0, -1 ); } + if ( $data === '' ) { + continue; + } + $result = call_user_func( $this->workCallback, $data ); + fwrite( $this->output, "$result\n" ); } } @@ -160,8 +166,12 @@ class OrderedStreamingForkController extends ForkController { $this->updateAvailableSockets( $sockets, $used, $sockets ? 0 : 5 ); } while ( !$sockets ); } - $data = trim( $data ); - if ( !$data ) { + if ( substr( $data, - 1 ) === "\n" ) { + // Strip any final new line used to delimit lines of input. + // The last line of input might not have it, though. + $data = substr( $data, 0, -1 ); + } + if ( $data === '' ) { continue; } $socket = array_pop( $sockets );