Compare the size of dynamic output of a function to a destination file, and do a rewrite
<p>I have a function to write a text file based on the form settings, a rather large form. </p>

<p>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.</p>

<p>Is it doable, BTW?</p>

<p>The process is, I fill up some forms:</p>

<ol>
<li><p>A single file is written to contain some "specific" selected options</p></li>
<li><p>Some "non-specific" options do not necessarily write anything to the file.</p></li>
</ol>

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

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

<p>This is what I tried:</p>

<pre><code>if ($output != file_get_contents($filepath)) {
  // save the data
}
</code></pre>

<p>But I felt so much delay of execution in this.</p>

<p>I found a almost similar issue here: <a href="http://stackoverflow.com/questions/3060125/can-i-use-file-get-contents-to-compare-two-files">Can I use file_get_contents() to compare two files?</a>, 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.</p>

<p>No sensitive data on the form, btw.
Any hint is very much appreciated.</p>

<p>Thanks</p>
