Is there a more efficient way to work with a binary file?
<p>I have a script that does a whole bunch of <code>fread</code> and <code>fseek</code> calls on a binary file, using a file pointer created like this:</p>

<pre><code>$fp = fopen('r','mybinaryfile');
</code></pre>

<p>The script deals with around 2,500 separate files within the binary, each of which attracts a number of <code>fseek</code> and <code>fread</code> calls, so total operations on the file pointer probably well exceeds 20,000.</p>

<p>Am I right in thinking that each of these calls using my <code>$fp</code> file pointer results in a physical read action on the disk?</p>

<p>If so, I'm wondering if it would be better to load the whole file into memory and work with it like that. Would it?</p>

<p>Currently when I run this script, it takes around 20 seconds. Seems to me like there is room for improvement.</p>

<p>EDIT: And also, if it is possible to bring the file into memory, how is that achieved, while sticking with the pointer approach? The files are only around 3MB each, so running out of memory shouldn't be an issue.</p>
