title: Grep search from end of file
body: <p>I have large log file 300-500 megs and need to do searches in it. I am currently doing this using grep in php code, but I want to further optimize the code.
  Data I need is always within last 10000 lines in the file so I want the search to start from the end and move forward until pattern is found and stop.</p>
  
  <p>I found some info that tac can do this but my performance tests show using tac is 4 times slower.
  Currently my search takes about 0.13 sec to complete with tac added on it takes 0.50. I feel like I am missing something, I would appreciate help.</p>
  
  <p>My expectation is that if I get file read from the end properly this will increase the speed of the process considerably.</p>
  
  <p>here is the code and it includes the timer</p>
  
  <pre><code>&lt;?php
  exec('grep -r "search var" file.log -b  | head -1', $result);
  echo $result[0];
  
  $time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
  echo "&lt;br&gt;".$time; 
  ?&gt;
  </code></pre>