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 7984271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:13:01+00:00 2026-06-04T11:13:01+00:00

I have a function to write a text file based on the form settings,

  • 0

I have a function to write a text file based on the form settings, a rather large form.

Shortly, I want to compare the output of a function to a single file, and only do execution (rewriting the file) if the destination file is different from the output. As you guess, it is a performance concern.

Is it doable, BTW?

The process is, I fill up some forms:

  1. A single file is written to contain some “specific” selected options

  2. Some “non-specific” options do not necessarily write anything to the file.

The form is updateable anytime, so the content of the file may grow or shrink based on different options.

It only needs a rewrite to the file if I am at point #1.
When at point #2, nothing should be written.

This is what I tried:

if ($output != file_get_contents($filepath)) {
  // save the data
}

But I felt so much delay of execution in this.

I found a almost similar issue here: Can I use file_get_contents() to compare two files?, but my issue is different. Mine is comparing the result of the process to an already existing file which simply the result of the process previously. And only rewrite the file if they are different.

No sensitive data on the form, btw.
Any hint is very much appreciated.

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-06-04T11:13:03+00:00Added an answer on June 4, 2026 at 11:13 am

    To compare a whole file with a string (I suppose it’s a string, isn’t it?) the only way is to read whole file and do comparison. To improve performance you can read file line by line and stop at first different line, as Explosion Pills said before me.

    If your file is really big, and you want to improve performance further, you can do some hashing stuff:

    • Generate the output, let’s say $output.
    • Calculate md5($output) and store in $output_md5.
    • Compare $output_md5 with a stored one, let’s say in file output.md5.
    • Are they equal?
      • If yes, do nothing.
      • If not, save $output into output.txt and $output_md5 in output.md5.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this script in the separate Sample.js file: function MyPrint(text) { document.write(text); }
I have this function which writes content to a text file: function write($text){ fwrite($this->fp,
I have problem with fancybox. I want to write a function that will run
I have a program which write logging as Text File. namespace logging { using
I have a text file that is almost sometimes 5 mb large. What I
I'm trying to write a function that does the following: Given a text file,
So I have a function call classifier that basically check all text file in
I have a function that calls out a read or write request on a
I have a function that I use quite frequently, which allows me to write
i have a function defined as follows: void AddHeadCode(std::ofstream &ostream, size_t length){ ostream.write((char*)length, sizeof(length));

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.