fflush_variation3.phpt 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. --TEST--
  2. Test fflush() function: usage variations - hard links as resource
  3. --SKIPIF--
  4. <?php
  5. if( substr(PHP_OS, 0, 3) == 'WIN')
  6. die("skip Links not valid on Windows");
  7. ?>
  8. --FILE--
  9. <?php
  10. /* Prototype: bool fflush ( resource $handle );
  11. Description: Flushes the output to a file
  12. */
  13. /* test fflush() with handle to hard links as resource */
  14. $file_path = dirname(__FILE__);
  15. require $file_path.'/file.inc';
  16. echo "*** Testing fflush(): with hard links to files opened in diff modes ***\n";
  17. $file_types = array("empty", "numeric", "text", "text_with_new_line", "alphanumeric");
  18. $file_modes = array("w", "wb", "wt", "w+", "w+b","w+t",
  19. "a", "ab", "at", "a+","a+b", "a+t");
  20. $file_name = "$file_path/fflush_variation3.tmp";
  21. $link_name = "$file_path/lnk_fflush_variation3.tmp";
  22. $count = 1;
  23. foreach( $file_types as $type ) {
  24. echo "-- Iteration $count with file containing $type data --\n";
  25. foreach( $file_modes as $mode ) {
  26. // creating the file
  27. $file_handle = fopen($file_name, "w");
  28. if($file_handle == false)
  29. exit("Error:failed to open file $file_name");
  30. // fill the fill with some data if mode is append mode
  31. if( substr($mode, 0, 1) == "a" )
  32. fill_file($file_handle, $type, 10);
  33. // fclose($file_handle);
  34. // creating hard link to the file
  35. var_dump( link($file_name, $link_name) );
  36. // opening the file in different modes
  37. $file_handle = fopen($link_name, $mode);
  38. if($file_handle == false)
  39. exit("Error:failed to open link $link_name");
  40. // writing data to the file
  41. var_dump( fill_file($file_handle, $type, 50) );
  42. var_dump( fflush($file_handle) );
  43. fclose($file_handle);
  44. // reading data from the file after flushing
  45. var_dump( readfile($link_name) );
  46. unlink($link_name);
  47. unlink($file_name);
  48. }
  49. $count++;
  50. }
  51. echo "\n*** Done ***";
  52. ?>
  53. --EXPECTF--
  54. *** Testing fflush(): with hard links to files opened in diff modes ***
  55. -- Iteration 1 with file containing empty data --
  56. bool(true)
  57. bool(true)
  58. bool(true)
  59. int(0)
  60. bool(true)
  61. bool(true)
  62. bool(true)
  63. int(0)
  64. bool(true)
  65. bool(true)
  66. bool(true)
  67. int(0)
  68. bool(true)
  69. bool(true)
  70. bool(true)
  71. int(0)
  72. bool(true)
  73. bool(true)
  74. bool(true)
  75. int(0)
  76. bool(true)
  77. bool(true)
  78. bool(true)
  79. int(0)
  80. bool(true)
  81. bool(true)
  82. bool(true)
  83. int(0)
  84. bool(true)
  85. bool(true)
  86. bool(true)
  87. int(0)
  88. bool(true)
  89. bool(true)
  90. bool(true)
  91. int(0)
  92. bool(true)
  93. bool(true)
  94. bool(true)
  95. int(0)
  96. bool(true)
  97. bool(true)
  98. bool(true)
  99. int(0)
  100. bool(true)
  101. bool(true)
  102. bool(true)
  103. int(0)
  104. -- Iteration 2 with file containing numeric data --
  105. bool(true)
  106. bool(true)
  107. bool(true)
  108. 22222222222222222222222222222222222222222222222222int(50)
  109. bool(true)
  110. bool(true)
  111. bool(true)
  112. 22222222222222222222222222222222222222222222222222int(50)
  113. bool(true)
  114. bool(true)
  115. bool(true)
  116. 22222222222222222222222222222222222222222222222222int(50)
  117. bool(true)
  118. bool(true)
  119. bool(true)
  120. 22222222222222222222222222222222222222222222222222int(50)
  121. bool(true)
  122. bool(true)
  123. bool(true)
  124. 22222222222222222222222222222222222222222222222222int(50)
  125. bool(true)
  126. bool(true)
  127. bool(true)
  128. 22222222222222222222222222222222222222222222222222int(50)
  129. bool(true)
  130. bool(true)
  131. bool(true)
  132. 222222222222222222222222222222222222222222222222222222222222int(60)
  133. bool(true)
  134. bool(true)
  135. bool(true)
  136. 222222222222222222222222222222222222222222222222222222222222int(60)
  137. bool(true)
  138. bool(true)
  139. bool(true)
  140. 222222222222222222222222222222222222222222222222222222222222int(60)
  141. bool(true)
  142. bool(true)
  143. bool(true)
  144. 222222222222222222222222222222222222222222222222222222222222int(60)
  145. bool(true)
  146. bool(true)
  147. bool(true)
  148. 222222222222222222222222222222222222222222222222222222222222int(60)
  149. bool(true)
  150. bool(true)
  151. bool(true)
  152. 222222222222222222222222222222222222222222222222222222222222int(60)
  153. -- Iteration 3 with file containing text data --
  154. bool(true)
  155. bool(true)
  156. bool(true)
  157. text text text text text text text text text text int(50)
  158. bool(true)
  159. bool(true)
  160. bool(true)
  161. text text text text text text text text text text int(50)
  162. bool(true)
  163. bool(true)
  164. bool(true)
  165. text text text text text text text text text text int(50)
  166. bool(true)
  167. bool(true)
  168. bool(true)
  169. text text text text text text text text text text int(50)
  170. bool(true)
  171. bool(true)
  172. bool(true)
  173. text text text text text text text text text text int(50)
  174. bool(true)
  175. bool(true)
  176. bool(true)
  177. text text text text text text text text text text int(50)
  178. bool(true)
  179. bool(true)
  180. bool(true)
  181. text text text text text text text text text text text text int(60)
  182. bool(true)
  183. bool(true)
  184. bool(true)
  185. text text text text text text text text text text text text int(60)
  186. bool(true)
  187. bool(true)
  188. bool(true)
  189. text text text text text text text text text text text text int(60)
  190. bool(true)
  191. bool(true)
  192. bool(true)
  193. text text text text text text text text text text text text int(60)
  194. bool(true)
  195. bool(true)
  196. bool(true)
  197. text text text text text text text text text text text text int(60)
  198. bool(true)
  199. bool(true)
  200. bool(true)
  201. text text text text text text text text text text text text int(60)
  202. -- Iteration 4 with file containing text_with_new_line data --
  203. bool(true)
  204. bool(true)
  205. bool(true)
  206. line
  207. line of text
  208. line
  209. line of text
  210. line
  211. line of tint(50)
  212. bool(true)
  213. bool(true)
  214. bool(true)
  215. line
  216. line of text
  217. line
  218. line of text
  219. line
  220. line of tint(50)
  221. bool(true)
  222. bool(true)
  223. bool(true)
  224. line
  225. line of text
  226. line
  227. line of text
  228. line
  229. line of tint(50)
  230. bool(true)
  231. bool(true)
  232. bool(true)
  233. line
  234. line of text
  235. line
  236. line of text
  237. line
  238. line of tint(50)
  239. bool(true)
  240. bool(true)
  241. bool(true)
  242. line
  243. line of text
  244. line
  245. line of text
  246. line
  247. line of tint(50)
  248. bool(true)
  249. bool(true)
  250. bool(true)
  251. line
  252. line of text
  253. line
  254. line of text
  255. line
  256. line of tint(50)
  257. bool(true)
  258. bool(true)
  259. bool(true)
  260. line
  261. line line
  262. line of text
  263. line
  264. line of text
  265. line
  266. line of tint(60)
  267. bool(true)
  268. bool(true)
  269. bool(true)
  270. line
  271. line line
  272. line of text
  273. line
  274. line of text
  275. line
  276. line of tint(60)
  277. bool(true)
  278. bool(true)
  279. bool(true)
  280. line
  281. line line
  282. line of text
  283. line
  284. line of text
  285. line
  286. line of tint(60)
  287. bool(true)
  288. bool(true)
  289. bool(true)
  290. line
  291. line line
  292. line of text
  293. line
  294. line of text
  295. line
  296. line of tint(60)
  297. bool(true)
  298. bool(true)
  299. bool(true)
  300. line
  301. line line
  302. line of text
  303. line
  304. line of text
  305. line
  306. line of tint(60)
  307. bool(true)
  308. bool(true)
  309. bool(true)
  310. line
  311. line line
  312. line of text
  313. line
  314. line of text
  315. line
  316. line of tint(60)
  317. -- Iteration 5 with file containing alphanumeric data --
  318. bool(true)
  319. bool(true)
  320. bool(true)
  321. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
  322. bool(true)
  323. bool(true)
  324. bool(true)
  325. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
  326. bool(true)
  327. bool(true)
  328. bool(true)
  329. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
  330. bool(true)
  331. bool(true)
  332. bool(true)
  333. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
  334. bool(true)
  335. bool(true)
  336. bool(true)
  337. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
  338. bool(true)
  339. bool(true)
  340. bool(true)
  341. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50)
  342. bool(true)
  343. bool(true)
  344. bool(true)
  345. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
  346. bool(true)
  347. bool(true)
  348. bool(true)
  349. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
  350. bool(true)
  351. bool(true)
  352. bool(true)
  353. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
  354. bool(true)
  355. bool(true)
  356. bool(true)
  357. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
  358. bool(true)
  359. bool(true)
  360. bool(true)
  361. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
  362. bool(true)
  363. bool(true)
  364. bool(true)
  365. ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60)
  366. *** Done ***