php文件写入问题
我有一个脚本,它不断地将字符串附加到文件中。
例如(这是一个测试脚本):
$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 );
}
但是由于未知原因,当文本文件达到文件大小 2097156 B 时,我的程序停止附加字符串。这不是磁盘空间问题,因为我仍然可以创建另一个文本文件,但仅限于相同的确切文件大小值。
我尝试使用其他 php 函数 fwrite、fputs 但仍然没有成功。
知道为什么会出现这个问题吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
似乎不太可能,但如果 PHP 的当前设置非常低,您可能会遇到 PHP 的
max_execution_time
问题。尝试增加 php.ini 中的值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你的循环没有意义。它永远不会改变$i。
没时间就试试吧。
Your loop doesnt make sense. It never changes $i.
Try it without the while.
有几个问题可能会导致此问题。
PHP 的错误输出对于识别哪些问题可能导致该问题非常有价值。
There are several issues that could cause this problem.
PHP's error output would be invaluable for identify which of these issues may have contributed to the problem.