need to have a shared memory array between PHP scripts
<p>So I have this <strong>a.php</strong> file that is doing a <strong>SELECT X FROM Y WHERE Z</strong>.<br>
<strong>a.php</strong> is called many times by users.<br>
I would like to keep track of the rows that have been served, so I'd like to keep a counter for each row.</p>

<p>The question I am asking is how can I keep track of these counters? Of course I can store them in the DB, but this would mean that many updates would have to take place on the server side for each user and updates on indexed columns consume time.</p>

<p>Another option I thought would be interesting was proposed on <a href="http://stackoverflow.com/questions/7105866/i-want-to-define-a-variable-with-superglobal-scope-in-php">this thread</a><br>
What I think is that using a server file (the session points to a local file on the server) would be interesting solution, but what is two or more users read the file about the same time? 
They would read the counter 7 for row #23, and then would write 8 back to the file. So if for example it were 3 users together, it means the counter is now 3-1 digits lagging behind. Thus instead of being 10 (7+3) it is only 7+2 = 9.</p>

<p>Your ideas? </p>
