title: Caching generated images with PHP
body: <p>I am trying to cache images which have been generated. You create a image by accessing the file by resize.php?width=x&amp;height=y.
  If the image of that width and height does not exist I use imagemagick to create it. However if it does exist it is served to the visitor.</p>
  
  <p>The !file_exists($name) check works fine so processing is not done when its not needed. However the images still take a while to load.</p>
  
  <p>Is my approach of readfile incorrect or have I set headers incorrectly?</p>
  
  <pre><code>if (!file_exists($name)) {
   //image processing here
  }
  header("Content-Type: image/png");
  header("Expires: Sat, 25 Jul 2020 10:00:00 GMT");
  readfile($name);
  </code></pre>
  
  <p>Thanks.</p>