Note that there are some explanatory texts on larger screens.

plurals
  1. POCaching variables in PHP
    text
    copied!<p>Long story short, I am looking for the best way to quickly and efficently store, mostly, boolean variables, like:</p> <ul> <li>Has current user viewed this page? (Boolean)</li> <li>Has current user voted for this page? (Boolean again)</li> <li>How many times today this user got points for voting? (Integer)</li> </ul> <p>These variables are going to be stored only for ONE day, that is at midnight each day they will be removed.</p> <p>I can think of five ways to accomplish this, but I don't know how to properly speedtest them, so I could certainly use some help with this.</p> <h2>1. Single File - Single Variable</h2> <p>The first idea is to store some variable in a file like this <code>&lt;?php $___XYZ = true;</code>, then include it and return <code>$___XYZ</code>. The problem is, most likely there are going to be hundreds of these variables and this can take potentially a lot of space (since, correct me if I am wrong, each file takes minimum ~4KB of space, depending on partition format). Big plus is ease of access, easy to work with, and easy to clear the whole thing at the beginning of a day (just delete the whole folder with contents). Any problems with speed of access?</p> <h2>2. Single File - Many Variables</h2> <p>I could store groups of variables in one file, in such fashion:</p> <pre><code>0:1 1:1 14:0 154:0 </code></pre> <p>Then use fgets to find and read the variable but what about writing mid-file? Can fwrite be used effectively? I am not really confident this way is much better than 1., but what do you think?</p> <h2>3. APC</h2> <p>Use apc_store and others to store, modify and access the data. I have three concerns here - I read somewhere that enabling APC can seriously slow down your site, that there are sometimes strange problems with caching, and am curious about how to effectively remove only the "daily" cache, and leave anything else I might have cached? And how fine is it with hundreds of thousands variables stored in it?</p> <h2>4. MySQL Database</h2> <p>I could create a table with two rows (name and variable) but... I have this feeling it will be painfully slow when compared to any from the above options.</p> <hr> <p>To sum it up - which of these ways to store variables in PHP is the best? Or maybe there is something even better?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload