开发者

php file writing problem

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.

An开发者_运维问答y idea why this problem occurs?


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


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 );


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜