为什么在用PHP写入文件后需要`fclose`? [英] Why do I need `fclose` after writing to a file in PHP?

查看:131
本文介绍了为什么在用PHP写入文件后需要`fclose`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么使用php写入文件后需要使用fclose($handle)函数完成操作?程序结束时不自动执行此操作吗?

Why do I need to finish by using the fclose($handle) function after writing to a file using php? Doesn't the program automatically do this when it ends?

推荐答案

是.但是,最好自己动手做.此外,在脚本其余部分的整个执行过程中,您将使文件保持打开状态,应避免这样做.因此,除非脚本编写完成后立即完成执行,否则基本上打开文件的时间会比您需要的时间长.

Yes. But, it's good practice to do it yourself. Also, you'll leave the file open during the entire exection of the remainder of the script, which you should avoid. So unless your script finishes execution directly after you're finished writing, you're basically leaving the file open longer than you need to.

这篇关于为什么在用PHP写入文件后需要`fclose`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆