title: Is this the most efficient way to get and remove first line in file?
body: <p>I have a script which, each time is called, gets the first line of a file. Each line is known to be exactly of the same length (32 alphanumeric chars) and terminates with "\r\n".
  After getting the first line, the script removes it.</p>
  
  <p>This is done in this way:</p>
  
  <pre><code>$contents = file_get_contents($file));
  $first_line = substr($contents, 0, 32);
  file_put_contents($file, substr($contents, 32 + 2)); //+2 because we remove also the \r\n
  </code></pre>
  
  <p>Obviously it works, but I was wondering whether there is a smarter (or more efficient) way to do this?</p>
  
  <p>In my simple solution I basically <strong>read and rewrite the entire file just to take and remove the first line</strong>.</p>