title: PHP Caching not working on Included File
body: <p>I have a web form that has an included file that outputs select options for states. The html looks like</p>
  
  <pre><code>    &lt;select name="state" id="state"&gt;
          &lt;option value=""&gt;--&lt;/option&gt;
          &lt;?php include ("resources/data/stateoptions.php"); ?&gt;
        &lt;/select&gt;
  </code></pre>
  
  <p>The state options makes a call to a web service so that the list of store locations is always current. It seems however that this contact form page runs exceptionally slow (much faster if I remove this include). So I want to cache the web service call. My state options file looks like this</p>
  
  <pre><code>&lt;?php
    $cachefile = "cache/states.html";
    $cachetime = 5 * 60; // 5 minutes
  
    // Serve from the cache if it is younger than $cachetime
    if (file_exists($cachefile) &amp;&amp; (time() - $cachetime &lt; filemtime($cachefile))) 
    {
       include($cachefile);
  
       echo "&lt;!-- Cached ".date('jS F Y H:i', filemtime($cachefile))." 
       --&gt;n";
  
       exit;
    }
  
    ob_start(); // start the output buffer
  ?&gt;
  
  &lt;?php
  //url of locations web service
  $serviceURL = 'http://webserviceurl/state';
  
  //query the webservice
  $string = file_get_contents($serviceURL);
  
  //decode the json response into an array
  $json_a=json_decode($string,true);
  
  foreach( $json_a as $State =&gt; $IdealState){
  $IdealState = $IdealState[State];
  $IdealState2 = str_replace(' ', '-', $IdealState);
  echo '&lt;option value='.$IdealState2.'&gt;'.$IdealState.'&lt;/option&gt;';
  }
  ?&gt;
  
  &lt;?php
  // open/create cache file and write data
  $fp = fopen($cachefile, 'w'); 
  // save the contents of output buffer to the file
  fwrite($fp, ob_get_contents()); 
  // close the file
  fclose($fp); 
  // Send the output to the browser
  ob_end_flush(); 
  ?&gt;
  </code></pre>
  
  <p>When I call this file directly, everything works as expected, and a states.html file is created. For some reason however when the stateoptions.php file is included in my contact form page, it never creates a cache file, and the speed problem persists. I'm a fairly novice programmer, so any help would be much appreciated.</p>
  
  <p>Thanks!</p>