1

in Php i have written a code like below

//Example Code

foreach($arrayitem as $arr) //$arrayitem is having some array data
{
 $fp=fopen($arr.'.xls','w');

 for(condition)
 {
  //here i'm getting full content of an webpage(huge data) and some regexp to match data

  preg_match(regexp,getContent of an URL,$output);

  fputs($fp,$output);
 }
fclose($fp);
}

The idea here is to create a file and write the data in the $output variable and then creating the second file and writing the $output in that file and so on up-to the all values in the $arrayitem get finishes.

  • but what i have observed is that the second file and other consecutive files are getting created before the completion of the first file
  • And the file size is increasing slowly(on refresh the file size is changing)

how this can be possible ? what is actually happening here? normally the next file should be created only after completion of the first file right?

ɹɐqʞɐ zoɹǝɟ
  • 4,342
  • 3
  • 22
  • 35
  • If you can, I'd consider collecting all the data for a single file in one go and then writing with `file_put_contents`. It's simpler code, particularly when you add in exception handling to deal with possible dangling file handles. Obviously this would depend on the size of files you're writing, etc. – Rob Baillie Mar 18 '14 at 17:49
  • 1
    thanks for the reply,but i want to know why it is happening like that? – ɹɐqʞɐ zoɹǝɟ Mar 18 '14 at 17:50

0 Answers0