fdatasync.phpt 1.7 KB

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