title: PHP global variable persistent across requests
body: <p><strong>I need a global variable to be persistent across requests</strong></p>
  
  <p>I'm aware of a similar question <a href="https://stackoverflow.com/questions/26984067/php-persist-variable-across-all-requests">PHP Persist variable across all requests</a> but I'm concerned about what solution performs better because <strong>as the variable is <code>global</code> it must be set for every request.</strong></p>
  
  <p>So far the solutions that I can think of are</p>
  
  <p><strong>1. storing the value to the database.</strong></p>
  
  <p>But every request have one more hit on the db.</p>
  
  <p><strong>2. storing the value into a file</strong></p>
  
  <p>But every request hits the filesystem.
  On *nix systems the disk access is cached so further reading should be from RAM and thus not hitting the drive.</p>
  
  <p><strong>3. storing the value into a php include file and including that file at the main entry point of the web app.</strong></p>
  
  <p>The file instead of the raw value of the variable would contain a <code>define</code></p>
  
  <p><code>define("THE_GLOBAL", "ABC");</code></p>
  
  <p>Same concerns of (2) plus as php cache is active it may happen that the value isn't actually updated until the cache has a refresh.</p>
  
  <p><strong>4. using nosql like <em>redis</em></strong></p>
  
  <p>I don't like to set up redis just for that. Plus the variable have to be persistent across restarts of the web application or reboots of the system.
  And implementing this would require extra work.</p>
  
  <hr>
  
  <p>I think the best solution is <strong>(2)</strong>. But maybe I'm wrong.</p>
  
  <p>Any indication or suggestion supported by valid arguments would be very welcome.</p>