下一个文件是在PHP中第一个文件完成之前创建的?
在Php中,我编写了如下代码下一个文件是在PHP中第一个文件完成之前创建的?,php,file,buffer,fopen,fputs,Php,File,Buffer,Fopen,Fputs,在Php中,我编写了如下代码 //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_matc
//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);
}
这里的想法是创建一个文件并将数据写入$output变量,然后创建第二个文件并将$output写入该文件,依此类推,直到
$arrayitem完成
但我观察到的是,第二个文件和其他
在第一个文件完成之前,将创建连续的文件
并且文件大小增长缓慢刷新时文件大小为
改变
这怎么可能呢?
这里到底发生了什么?
通常只有在完成第一个文件后才能创建下一个文件,对吗如果可以的话,我会考虑一次收集一个文件的所有数据,然后用FielePtux内容编写。它的代码更简单,特别是当您添加异常处理来处理可能的悬空文件句柄时。很明显,这取决于你正在写的文件的大小,等等。谢谢你的回复,但我想知道为什么会这样?