Home Menu

fflush

Flushes the output to a file

Syntax

fflush ( resource $handle ) : bool

Parameters

handle

The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()).

Return

Returns TRUE on success or FALSE on failure.

Examples

<?

$filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/txt/file.txt';
$mode = 'r+';

$handle = fopen($filename, $mode);

    $contents = fread($handle, filesize($filename));
    
    rewind($handle);
    fwrite($handle, $contents);
    
    rewind($handle);
    $contents = fread($handle, filesize($filename));
    echo "fwrite without fflush: $contents" . PHP_EOL;
    
    rewind($handle);
    fwrite($handle, $contents);
    fflush($handle);
    
    rewind($handle);
    $contents = fread($handle, filesize($filename));
    echo "fwrite with fflush:    $contents";

fclose($handle);

?>
fwrite without fflush: Hello
fwrite with fflush:    Hello

PHP

JesusBible
HTMLCSSJSPHPSVGMore
AboutTerms