Jump to content

dynamically creating a file


jnroche
 Share

Recommended Posts

  • 2 weeks later...

It depends if you care about your data or not.

Generally, it's always a good idea to close a file when you're done with it. It's very easy for something to go wrong and corrupt a file that hasn't been closed properly. If you're concerned about efficiency, the overhead is negligible.
In addition to that, not closing files can also cause memory leaks (if file resources in memory are continually allocated without being freed), and if the file is locked while you have it opened and another application is trying to use it, the application will be waiting until the file gets closed and unlocked.So, yeah, it's always a good idea to close your files as soon as you can. If I'm working with file data and need to use fopen instead of file_get_contents, I use fopen, fread the entire thing, fclose, and then work on the data after I've closed the file. It's always a good practice to try and do things this way, if I looked at code that did not use fclose I would consider it a bug and fix it.
Link to comment
Share on other sites

It depends if you care about your data or not.In addition to that, not closing files can also cause memory leaks (if file resources in memory are continually allocated without being freed), and if the file is locked while you have it opened and another application is trying to use it, the application will be waiting until the file gets closed and unlocked.So, yeah, it's always a good idea to close your files as soon as you can. If I'm working with file data and need to use fopen instead of file_get_contents, I use fopen, fread the entire thing, fclose, and then work on the data after I've closed the file. It's always a good practice to try and do things this way, if I looked at code that did not use fclose I would consider it a bug and fix it.
thanks heaps guys!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...