Why do I need `fclose` after writing to a file in PHP?

前端 未结 7 948
囚心锁ツ
囚心锁ツ 2020-12-29 03:44

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?

7条回答
  •  既然无缘
    2020-12-29 04:07

    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.

提交回复
热议问题