来自php脚本的警告
E_WARNING: fclose():6不是有效的流资源
if($handle = opendir($dir)){
//do stuff
if(is_resource($handle)){
fclose($handle);
}
}在php中搜索它会得到一些较旧的bug报告,其中主要关注的是closedir()接受资源,但看起来fclose()应该接受从opendir返回的资源。
我还没有找到任何关于php中资源类型的通用最佳实践,以及如何正确地关闭它们。
此警告的后果是什么?我是不是遇到了内存泄漏或类似的问题?
发布于 2014-03-04 19:51:38
根据Docs的说法,你被支持用closedir($dh);来结束一个目录,
如下所示:
<?php
$dir = "/etc/php5/";
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
}
closedir($dh);
}
}
?>https://stackoverflow.com/questions/22170567
复制相似问题