- $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 );