这是我到目前为止的代码,我想知道它是否正确?
$handle = fopen($file, 'w') or die("can't open file");
$closed = fclose($handle);
while($closed){
DOAWESOMETHINGS(); // btw I only want to have this run once for each handle
$closed = false;
}
太感谢了!
这是我到目前为止的代码,我想知道它是否正确?
$handle = fopen($file, 'w') or die("can't open file");
$closed = fclose($handle);
while($closed){
DOAWESOMETHINGS(); // btw I only want to have this run once for each handle
$closed = false;
}
太感谢了!
您可以使用此语句检查句柄是否已关闭
if(!is_resource($handle)){
//Handle closed
}else{
//Handle still open
}
因此,如果您需要确保 fclose 在运行下一个函数之前已经工作,您可以使用这个循环:
while(is_resource($handle)){
//Handle still open
fclose($handle);
}
do_awesome_things();
注意:您还应该break;
在需要时使用 to 结束 while 循环。在这种情况下,直到句柄关闭,循环才会结束。