1--TEST-- 2Test fflush() function: usage variations - files in different modes 3--SKIPIF-- 4<?php 5if( substr(PHP_OS, 0, 3) == "WIN" ) 6 die("skip.. only for linux"); 7?> 8--FILE-- 9<?php 10 11/* test fflush() with handle of files opened in different modes */ 12 13$file_path = __DIR__; 14require $file_path.'/file.inc'; 15 16echo "*** Testing fflush(): with various types of files ***\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 "x", "xb", "xt", "x+", "x+b", "x+t"); 21 22$file_name = "$file_path/fflush_variation1.tmp"; 23 24$count = 1; 25 26foreach( $file_types as $type ) { 27 echo "-- Iteration $count with file containing $type Data--\n"; 28 foreach( $file_modes as $mode ) { 29 echo "-- File opened in $mode mode --\n"; 30 31 // creating the file except for x mode 32 if( substr($mode, 0, 1) != "x" ) { 33 $file_handle = fopen($file_name, "w"); 34 if($file_handle == false) 35 exit("Error:failed to open file $file_name"); 36 37 // filling the file with some data if mode is append mode 38 if( substr($mode, 0, 1) == "a") 39 fill_file($file_handle, $type, 10); 40 fclose($file_handle); 41 42 } 43 44 // opening the file in different modes 45 $file_handle = fopen($file_name, $mode); 46 if($file_handle == false) 47 exit("Error:failed to open file $file_name"); 48 49 // writing data to the file 50 var_dump( fill_file($file_handle, $type, 50) ); 51 var_dump( fflush($file_handle) ); 52 fclose($file_handle); 53 54 // reading the contents of the file after flushing 55 var_dump( readfile($file_name) ); 56 unlink($file_name); 57 } 58 $count++; 59} 60 61echo "\n*** Done ***"; 62?> 63--EXPECT-- 64*** Testing fflush(): with various types of files *** 65-- Iteration 1 with file containing empty Data-- 66-- File opened in w mode -- 67bool(true) 68bool(true) 69int(0) 70-- File opened in wb mode -- 71bool(true) 72bool(true) 73int(0) 74-- File opened in wt mode -- 75bool(true) 76bool(true) 77int(0) 78-- File opened in w+ mode -- 79bool(true) 80bool(true) 81int(0) 82-- File opened in w+b mode -- 83bool(true) 84bool(true) 85int(0) 86-- File opened in w+t mode -- 87bool(true) 88bool(true) 89int(0) 90-- File opened in a mode -- 91bool(true) 92bool(true) 93int(0) 94-- File opened in ab mode -- 95bool(true) 96bool(true) 97int(0) 98-- File opened in at mode -- 99bool(true) 100bool(true) 101int(0) 102-- File opened in a+ mode -- 103bool(true) 104bool(true) 105int(0) 106-- File opened in a+b mode -- 107bool(true) 108bool(true) 109int(0) 110-- File opened in a+t mode -- 111bool(true) 112bool(true) 113int(0) 114-- File opened in x mode -- 115bool(true) 116bool(true) 117int(0) 118-- File opened in xb mode -- 119bool(true) 120bool(true) 121int(0) 122-- File opened in xt mode -- 123bool(true) 124bool(true) 125int(0) 126-- File opened in x+ mode -- 127bool(true) 128bool(true) 129int(0) 130-- File opened in x+b mode -- 131bool(true) 132bool(true) 133int(0) 134-- File opened in x+t mode -- 135bool(true) 136bool(true) 137int(0) 138-- Iteration 2 with file containing numeric Data-- 139-- File opened in w mode -- 140bool(true) 141bool(true) 14222222222222222222222222222222222222222222222222222int(50) 143-- File opened in wb mode -- 144bool(true) 145bool(true) 14622222222222222222222222222222222222222222222222222int(50) 147-- File opened in wt mode -- 148bool(true) 149bool(true) 15022222222222222222222222222222222222222222222222222int(50) 151-- File opened in w+ mode -- 152bool(true) 153bool(true) 15422222222222222222222222222222222222222222222222222int(50) 155-- File opened in w+b mode -- 156bool(true) 157bool(true) 15822222222222222222222222222222222222222222222222222int(50) 159-- File opened in w+t mode -- 160bool(true) 161bool(true) 16222222222222222222222222222222222222222222222222222int(50) 163-- File opened in a mode -- 164bool(true) 165bool(true) 166222222222222222222222222222222222222222222222222222222222222int(60) 167-- File opened in ab mode -- 168bool(true) 169bool(true) 170222222222222222222222222222222222222222222222222222222222222int(60) 171-- File opened in at mode -- 172bool(true) 173bool(true) 174222222222222222222222222222222222222222222222222222222222222int(60) 175-- File opened in a+ mode -- 176bool(true) 177bool(true) 178222222222222222222222222222222222222222222222222222222222222int(60) 179-- File opened in a+b mode -- 180bool(true) 181bool(true) 182222222222222222222222222222222222222222222222222222222222222int(60) 183-- File opened in a+t mode -- 184bool(true) 185bool(true) 186222222222222222222222222222222222222222222222222222222222222int(60) 187-- File opened in x mode -- 188bool(true) 189bool(true) 19022222222222222222222222222222222222222222222222222int(50) 191-- File opened in xb mode -- 192bool(true) 193bool(true) 19422222222222222222222222222222222222222222222222222int(50) 195-- File opened in xt mode -- 196bool(true) 197bool(true) 19822222222222222222222222222222222222222222222222222int(50) 199-- File opened in x+ mode -- 200bool(true) 201bool(true) 20222222222222222222222222222222222222222222222222222int(50) 203-- File opened in x+b mode -- 204bool(true) 205bool(true) 20622222222222222222222222222222222222222222222222222int(50) 207-- File opened in x+t mode -- 208bool(true) 209bool(true) 21022222222222222222222222222222222222222222222222222int(50) 211-- Iteration 3 with file containing text Data-- 212-- File opened in w mode -- 213bool(true) 214bool(true) 215text text text text text text text text text text int(50) 216-- File opened in wb mode -- 217bool(true) 218bool(true) 219text text text text text text text text text text int(50) 220-- File opened in wt mode -- 221bool(true) 222bool(true) 223text text text text text text text text text text int(50) 224-- File opened in w+ mode -- 225bool(true) 226bool(true) 227text text text text text text text text text text int(50) 228-- File opened in w+b mode -- 229bool(true) 230bool(true) 231text text text text text text text text text text int(50) 232-- File opened in w+t mode -- 233bool(true) 234bool(true) 235text text text text text text text text text text int(50) 236-- File opened in a mode -- 237bool(true) 238bool(true) 239text text text text text text text text text text text text int(60) 240-- File opened in ab mode -- 241bool(true) 242bool(true) 243text text text text text text text text text text text text int(60) 244-- File opened in at mode -- 245bool(true) 246bool(true) 247text text text text text text text text text text text text int(60) 248-- File opened in a+ mode -- 249bool(true) 250bool(true) 251text text text text text text text text text text text text int(60) 252-- File opened in a+b mode -- 253bool(true) 254bool(true) 255text text text text text text text text text text text text int(60) 256-- File opened in a+t mode -- 257bool(true) 258bool(true) 259text text text text text text text text text text text text int(60) 260-- File opened in x mode -- 261bool(true) 262bool(true) 263text text text text text text text text text text int(50) 264-- File opened in xb mode -- 265bool(true) 266bool(true) 267text text text text text text text text text text int(50) 268-- File opened in xt mode -- 269bool(true) 270bool(true) 271text text text text text text text text text text int(50) 272-- File opened in x+ mode -- 273bool(true) 274bool(true) 275text text text text text text text text text text int(50) 276-- File opened in x+b mode -- 277bool(true) 278bool(true) 279text text text text text text text text text text int(50) 280-- File opened in x+t mode -- 281bool(true) 282bool(true) 283text text text text text text text text text text int(50) 284-- Iteration 4 with file containing text_with_new_line Data-- 285-- File opened in w mode -- 286bool(true) 287bool(true) 288line 289line of text 290line 291line of text 292line 293line of tint(50) 294-- File opened in wb mode -- 295bool(true) 296bool(true) 297line 298line of text 299line 300line of text 301line 302line of tint(50) 303-- File opened in wt mode -- 304bool(true) 305bool(true) 306line 307line of text 308line 309line of text 310line 311line of tint(50) 312-- File opened in w+ mode -- 313bool(true) 314bool(true) 315line 316line of text 317line 318line of text 319line 320line of tint(50) 321-- File opened in w+b mode -- 322bool(true) 323bool(true) 324line 325line of text 326line 327line of text 328line 329line of tint(50) 330-- File opened in w+t mode -- 331bool(true) 332bool(true) 333line 334line of text 335line 336line of text 337line 338line of tint(50) 339-- File opened in a mode -- 340bool(true) 341bool(true) 342line 343line line 344line of text 345line 346line of text 347line 348line of tint(60) 349-- File opened in ab mode -- 350bool(true) 351bool(true) 352line 353line line 354line of text 355line 356line of text 357line 358line of tint(60) 359-- File opened in at mode -- 360bool(true) 361bool(true) 362line 363line line 364line of text 365line 366line of text 367line 368line of tint(60) 369-- File opened in a+ mode -- 370bool(true) 371bool(true) 372line 373line line 374line of text 375line 376line of text 377line 378line of tint(60) 379-- File opened in a+b mode -- 380bool(true) 381bool(true) 382line 383line line 384line of text 385line 386line of text 387line 388line of tint(60) 389-- File opened in a+t mode -- 390bool(true) 391bool(true) 392line 393line line 394line of text 395line 396line of text 397line 398line of tint(60) 399-- File opened in x mode -- 400bool(true) 401bool(true) 402line 403line of text 404line 405line of text 406line 407line of tint(50) 408-- File opened in xb mode -- 409bool(true) 410bool(true) 411line 412line of text 413line 414line of text 415line 416line of tint(50) 417-- File opened in xt mode -- 418bool(true) 419bool(true) 420line 421line of text 422line 423line of text 424line 425line of tint(50) 426-- File opened in x+ mode -- 427bool(true) 428bool(true) 429line 430line of text 431line 432line of text 433line 434line of tint(50) 435-- File opened in x+b mode -- 436bool(true) 437bool(true) 438line 439line of text 440line 441line of text 442line 443line of tint(50) 444-- File opened in x+t mode -- 445bool(true) 446bool(true) 447line 448line of text 449line 450line of text 451line 452line of tint(50) 453-- Iteration 5 with file containing alphanumeric Data-- 454-- File opened in w mode -- 455bool(true) 456bool(true) 457ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50) 458-- File opened in wb mode -- 459bool(true) 460bool(true) 461ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50) 462-- File opened in wt mode -- 463bool(true) 464bool(true) 465ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50) 466-- File opened in w+ mode -- 467bool(true) 468bool(true) 469ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50) 470-- File opened in w+b mode -- 471bool(true) 472bool(true) 473ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50) 474-- File opened in w+t mode -- 475bool(true) 476bool(true) 477ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50) 478-- File opened in a mode -- 479bool(true) 480bool(true) 481ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60) 482-- File opened in ab mode -- 483bool(true) 484bool(true) 485ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60) 486-- File opened in at mode -- 487bool(true) 488bool(true) 489ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60) 490-- File opened in a+ mode -- 491bool(true) 492bool(true) 493ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60) 494-- File opened in a+b mode -- 495bool(true) 496bool(true) 497ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60) 498-- File opened in a+t mode -- 499bool(true) 500bool(true) 501ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(60) 502-- File opened in x mode -- 503bool(true) 504bool(true) 505ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50) 506-- File opened in xb mode -- 507bool(true) 508bool(true) 509ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50) 510-- File opened in xt mode -- 511bool(true) 512bool(true) 513ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50) 514-- File opened in x+ mode -- 515bool(true) 516bool(true) 517ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50) 518-- File opened in x+b mode -- 519bool(true) 520bool(true) 521ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50) 522-- File opened in x+t mode -- 523bool(true) 524bool(true) 525ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 ab12 int(50) 526 527*** Done *** 528