Read active log files without needing a temp file
<p>I am developing a script to read and search log files for a big system at work.
It currently works like this:</p>

<ol>
<li>User defines search parameters</li>
<li>PHP uses shell_exec("tac logfile.log > tmpfile.log") to copy log file (and reverse the lines) to a temp file</li>
<li>PHP fopen()'s the temp file</li>
<li>PHP reads through each line of the file and applies the search parameters</li>
<li>PHP deletes the temp file made in #2</li>
</ol>

<p>I decided upon this method as the log files are written to every few seconds, and I need to read the log file backwards.</p>

<p>My problem is that step #2 takes a really long time when the log file is >300MB, and each day's log file is easily 500MB, so searching this much data is really time consuming.</p>

<p>I have a couple of questions:</p>

<ol>
<li>Can I simply run fopen() on the active log file? </li>
<li>Can it cause corruption of the log file if I do simply read it while other scripts are writing to it?</li>
<li>Will it slow down the scripts writing to the log file if I am reading it at the same time?</li>
<li>Can I tell PHP to read each line of the file backwards rather than forwards?</li>
</ol>

<p>I hope that makes sense...</p>
