title: What is the best way to write a large file to disk in PHP?
body: <p>I have a PHP script that occasionally needs to write large files to disk. Using <code>file_put_contents()</code>, if the file is large enough (in this case around 2 MB), the PHP script runs out of memory (PHP Fatal error:  Allowed memory size of ######## bytes exhausted). I know I could just increase the memory limit, but that doesn't seem like a full solution to me--there has to be a better way, right?</p>
  
  <p><strong>What is the best way to write a large file to disk in PHP?</strong></p>