Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

fflush

Description

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

1

<?

$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
HomeMenu