}
if ( $channel === null ) {
$this->cleanupChanneled();
-
- $f = fopen( 'php://stdout', 'a' );
- fwrite( $f, $out );
- fclose( $f );
+ if( php_sapi_name() == 'cli' ) {
+ fwrite( STDOUT, $out );
+ } else {
+ print( $out );
+ }
}
else {
$out = preg_replace( '/\n\z/', '', $out );
if ( php_sapi_name() == 'cli' ) {
fwrite( STDERR, $err . "\n" );
} else {
- $f = fopen( 'php://stderr', 'a' );
- fwrite( $f, $err . "\n" );
- fclose( $f );
+ print $err;
}
$die = intval( $die );
if ( $die > 0 ) {
*/
public function cleanupChanneled() {
if ( !$this->atLineStart ) {
- $handle = fopen( 'php://stdout', 'w' );
- fwrite( $handle, "\n" );
- fclose( $handle );
+ if( php_sapi_name() == 'cli' ) {
+ fwrite( STDOUT, "\n" );
+ } else {
+ print "\n";
+ }
$this->atLineStart = true;
}
}
return;
}
- $handle = fopen( 'php://stdout', 'a' );
+ $cli = php_sapi_name() == 'cli';
// End the current line if necessary
if ( !$this->atLineStart && $channel !== $this->lastChannel ) {
- fwrite( $handle, "\n" );
+ if( $cli ) {
+ fwrite( STDOUT, "\n" );
+ } else {
+ print "\n";
+ }
}
- fwrite( $handle, $msg );
+ if( $cli ) {
+ fwrite( STDOUT, $msg );
+ } else {
+ print $msg;
+ }
$this->atLineStart = false;
if ( $channel === null ) {
// For unchanneled messages, output trailing newline immediately
- fwrite( $handle, "\n" );
+ if( $handle ) {
+ fwrite( STDOUT, "\n" );
+ } else {
+ print "\n";
+ }
$this->atLineStart = true;
}
$this->lastChannel = $channel;
-
- // Cleanup handle
- fclose( $handle );
}
/**