fflush_variation3.phpt 7.0 KB

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