title: Write data to start of file when not enough space
body: <p><strong>The problem</strong></p>
  
  <p>How to write data to start of file if I have not enough space to allocate it in RAM and I have not enough space to make it's copy on current FS partition? I.e. I have a file with <code>100Mb</code> size, I have <code>30Mb</code> memory limit in my PHP script (and it can not be adjusted in any way) and I have only <code>50Mb</code> free on my current FS partition. I want to add 2-10 rows to file (it's definitely less than remaining 50Mb FS space)</p>
  
  <p><em>Some background</em></p>
  
  <p>I know about <a href="https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem">XY-problem</a> and agree that it's true for this case. But to reconsider this case I'll need to change significant part of current application (actually, it went from previous team) and, may be, API of other applications that using this file.</p>
  
  <p><strong>My attempt</strong></p>
  
  <p>I have not found solution for this yet. My previous approach was - to use some network buffer (i.e. to connect to some external storage, such as MySQL, for example - it's located on another machine where there is enough space to write file's copy)</p>
  
  <p><strong>The question</strong></p>
  
  <p>So, is it possible to write data to file's start when I have not enough space to allocate it in RAM and have not enough space to create file's copy on FS? Is using network (external) storage the only solution?</p>