1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
--TEST--
Test fsync() function: basic functionality
--FILE--
<?php
echo "*** Testing fsync(): writing to a file and reading the contents ***\n";
$data = <<<EOD
first line of string
second line of string
third line of string
EOD;
$file_path = __DIR__;
$filename = "$file_path/fsync_basic.tmp";
// opening a file
$file_handle = fopen($filename, "w");
if($file_handle == false)
exit("Error:failed to open file $filename");
if(PHP_OS_FAMILY == 'Windows') {
$data = str_replace("\r",'', $data);
}
// writing data to the file
var_dump( fwrite($file_handle, $data) );
var_dump( fsync($file_handle) );
var_dump( readfile($filename) );
echo "\n*** Testing fsync(): for return type ***\n";
$return_value = fsync($file_handle);
var_dump( is_bool($return_value) );
fclose($file_handle);
echo "\n*** Testing fsync(): attempting to sync stdin ***\n";
$file_handle = fopen("php://stdin", "w");
var_dump(fsync($file_handle));
fclose($file_handle);
echo "\n*** Testing fsync(): for non-file stream ***\n";
$file_handle = fopen("php://memory", "w");
$return_value = fsync($file_handle);
var_dump( ($return_value) );
fclose($file_handle);
echo "\n*** Done ***";
?>
--CLEAN--
<?php
$file_path = __DIR__;
$filename = "$file_path/fsync_basic.tmp";
unlink($filename);
?>
--EXPECTF--
*** Testing fsync(): writing to a file and reading the contents ***
int(63)
bool(true)
first line of string
second line of string
third line of stringint(63)
*** Testing fsync(): for return type ***
bool(true)
*** Testing fsync(): attempting to sync stdin ***
bool(false)
*** Testing fsync(): for non-file stream ***
Warning: fsync(): Can't fsync this stream! in %s on line %d
bool(false)
*** Done ***
|