1

I have a script which constanly append strings into a file.

For example (this is a test script):

$i = 1;
$file = 'wikipedia/test.txt';
$text = 'the quick brown fox jumps over the lazy dog';
while($i!=0)
{
  file_put_contents($file, $text, FILE_APPEND );
}

But for an unknown reason my program stops appending strings when the text file reached the file size of 2097156 B . It wasn't a disk space issue since i could still create another text file yet limited to the same exact file size value.

I tried using other php functions fwrite, fputs but still didn't work out.

Any idea why this problem occurs?

ralpu
  • 193
  • 3
  • 15
  • 2
    Please expand on "still didn't work out." Did you encounter exactly the same problem at exactly the same file size when using `fwrite` and `fputs`? – George Cummins Jul 08 '11 at 17:59
  • Yes.. same problem. It stops appending when it reached the said file size – ralpu Jul 08 '11 at 18:03

3 Answers3

1

Seems unlikely, but you might have run up against PHP's max_execution_time if its current setting is very low. Try increasing its value in php.ini

Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
0

Your loop doesnt make sense. It never changes $i. Try it without the while.

$file = 'wikipedia/test.txt';
$text = 'the quick brown fox jumps over the lazy dog';
file_put_contents($file, $text, FILE_APPEND );
sroes
  • 14,663
  • 1
  • 53
  • 72
0

There are several issues that could cause this problem.

  1. You may have encountered the max execution time limit ( default: 30 seconds ).
  2. You may have exhausted the memory limit ( default: varies by version)
  3. Something may have changed on disk ( the file permissions may have changed, or you may have exceeded a disk quota).

PHP's error output would be invaluable for identify which of these issues may have contributed to the problem.

George Cummins
  • 28,485
  • 8
  • 71
  • 90