fflush_basic.phpt 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. --TEST--
  2. Test fflush() function: basic functionality
  3. --FILE--
  4. <?php
  5. /* Prototype: bool fflush ( resource $handle );
  6. Description: Flushes the output to a file
  7. */
  8. echo "*** Testing fflush(): writing to a file and reading the contents ***\n";
  9. $data = <<<EOD
  10. first line of string
  11. second line of string
  12. third line of string
  13. EOD;
  14. $file_path = dirname(__FILE__);
  15. $filename = "$file_path/fflush_basic.tmp";
  16. // opening a file
  17. $file_handle = fopen($filename, "w");
  18. if($file_handle == false)
  19. exit("Error:failed to open file $filename");
  20. if(substr(PHP_OS, 0, 3) == "WIN") {
  21. $data = str_replace("\r",'', $data);
  22. }
  23. // writing data to the file
  24. var_dump( fwrite($file_handle, $data) );
  25. var_dump( fflush($file_handle) );
  26. var_dump( readfile($filename) );
  27. echo "\n*** Testing fflush(): for return type ***\n";
  28. $return_value = fflush($file_handle);
  29. var_dump( is_bool($return_value) );
  30. fclose($file_handle);
  31. echo "\n*** Done ***";
  32. ?>
  33. --CLEAN--
  34. <?php
  35. $file_path = dirname(__FILE__);
  36. $filename = "$file_path/fflush_basic.tmp";
  37. unlink($filename);
  38. ?>
  39. --EXPECTF--
  40. *** Testing fflush(): writing to a file and reading the contents ***
  41. int(63)
  42. bool(true)
  43. first line of string
  44. second line of string
  45. third line of stringint(63)
  46. *** Testing fflush(): for return type ***
  47. bool(true)
  48. *** Done ***