Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7543795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:31:14+00:00 2026-05-30T08:31:14+00:00

Hey so I’m trying to clean up my code a bit, and I just

  • 0

Hey so I’m trying to clean up my code a bit, and I just need to know: How important is the fopen function in PHP? By this I mean…well I’ve been told that you always need to fclose a file when you’re done with it. This leads me to believe that if a file stays open too long then it gets corrupt in some way?

I don’t know, but the thing is I’ve got an if statement that if the condition is true, it opens the file(s) and writes to it(them). Would it be just as efficient to open all the files for writing/reading at the beginning of the script, and then just include the instruction to actually write to them if the conditional is true??

And while we’re on the topic…if I want to read line by line from a file I’ll simply use the array = file(“filename) shortcut I learned here. Is there a shortcut for writing to a file as well, without having to go through all the fopen stuff? Can I take a file and make it an array, line by line, and by changing that array, change the file? Is there anyway to do that?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:31:15+00:00Added an answer on May 30, 2026 at 8:31 am

    if a file stays open too long then it gets corrupt in some way?

    I think PHP is smart enough to garbage collect your open files when you are finishing using them. I don’t think the file will be corrupted if you don’t close it unless you write to it unintentionally.

    Would it be just as efficient to open all the files for writing/reading at the beginning of the script

    I’m not sure you should worry about efficiency unless you need to. If your code is working and is maintainable, I wouldn’t change where you open files.

    Is there a shortcut for writing to a file as well, without having to go through all the fopen stuff?

    You can use file_put_contents(..) as a shortcut to write to files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey guys I have the follow code in js: $(document).ready(function(){ $(.replyLink).click(function(){ $(#form-to-+this.id).html(htmlForm()).toggle(500); return false;
Hey am just curious to know if this can be done! I want to
Hey I need a little help with unsigned char bit access. I need to
Hey guys I'm running this code in Android: public ServiceServer(String serverName) { this.serverName =
Hey, I'm trying to get the source code of an app similar to the
Hey! I am trying to get ant installed and actually already did following this
Hey all, I'm using this code to change my sIFR (version 3) H1 and
Hey guys, I'm working on a project. I need to use the function cvFindHomography
Hey, PHP newbie here when I try to run this to get an IP
Hey guys I am getting this exception when trying to run the query Column

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.