Created
March 28, 2017 19:55
-
-
Save humbertocastelo/b5b4256c5b70efe57a3bdd218e65eceb to your computer and use it in GitHub Desktop.
Print Flush
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting( E_ALL ); | |
ini_set( 'display_errors', true ); | |
if ( !headers_sent() ) { | |
header( 'X-Accel-Buffering: no' ); | |
} | |
function is_apache2() { | |
static $bool; | |
if ( isset( $bool ) ) { | |
return $bool; | |
} | |
$bool = ( php_sapi_name() !== 'cli' ); | |
return $bool; | |
} | |
function print_flush( $input ) { | |
if ( is_apache2() ) { | |
print $input; | |
ob_flush(); | |
flush(); | |
} else { | |
print strip_tags( str_replace( array( '<br/>', '<br>' ), "\x0a", $input ) ); | |
} | |
} | |
print_flush( 'Oi' . '<br/>' ); sleep(5); | |
print_flush( 'Eu sou o Goku' . '<br/>' ); sleep(5); | |
print_flush( "\x0a" ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment