title: Laravel Headers and Caching in php
body: <p>I have a small image generator as part of my laravel4 application. It takes about 700ms to generate the image and so I have started caching the generated result on my server and returning that to the browser instead which saves some time.</p>
  
  <p>As the image will never change once generated I wanted to tell the browser to cache the image locally and I have done this with the following code:</p>
  
  <pre><code>$path = $cacheFolderPath . $cacheFileName;
  
  if (File::exists( $path )){
      $response = Response::make(File::get($path));
      $response-&gt;header('Content-Type', 'image/png');
      $response-&gt;header('Content-Disposition', 'inline; filename="'.$cacheFileName.'"');
      $response-&gt;header('Content-Transfer-Encoding', 'binary');
      $response-&gt;header('Cache-Control', 'public, max-age=10800, pre-check=10800');
      $response-&gt;header('Pragma', 'public');
      $response-&gt;header('Expires', date(DATE_RFC822,strtotime(" 2 day")) );
      $response-&gt;header('Last-Modified', date(DATE_RFC822, File::lastModified($path)) );
      $response-&gt;header('Content-Length', filesize($path));
      return $response;
  }
  </code></pre>
  
  <p>This sends an image with status code <code>200 OK</code> to the browser with the following headers:</p>
  
  <pre><code>Cache-Control:max-age=10800, pre-check=10800, public
  Connection:Keep-Alive
  Content-Disposition:inline; filename="pie_0_normal.png"
  Content-Length:2129
  Content-Transfer-Encoding:binary
  Content-Type:image/png
  Date:Wed, 07 Aug 2013 10:29:20 GMT
  Expires:Fri, 09 Aug 13 10:29:20 +0000
  Keep-Alive:timeout=5, max=93
  Last-Modified:Wed, 07 Aug 13 10:14:42 +0000
  Pragma:public
  Server:Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7
  Set-Cookie:laravel_session=767487mhf6j2btv3k01vu56174; expires=Wed, 07-Aug-2013 12:29:20 GMT; path=/; httponly
  X-Powered-By:PHP/5.4.7
  </code></pre>
  
  <p>My issue is that my browser (chrome, not tested in others) still refuses to simply grab the local cached version and instead hits the server again.</p>
  
  <p>I have spent about half an hour searching for other questions on this subject and all of them have given me answers which I have incorporated into the above code. So while I know that there are similar questions, this one is unique to the above source code. </p>
  
  <p><strong>My question is</strong>, what am I doing wrong that would result in the file not being cached by the browser?</p>