title: Varnish Cache not Caching PHP with Sessions Unless backend TTL altered
body: <p>I'm new to Varnish Cache and have a question I hope I can get some help with.</p>
  
  <p>I have a very simple and basic setup but it's not working as I understand
  it should for some reason.</p>
  
  <p>It's related to Varnish not caching PHP pages that are using cookies.</p>
  
  <p>Here is my setup:</p>
  
  <p>1) For my default.vcl I have a simple backend</p>
  
  <pre><code>backend default {
  .host = "127.0.0.1";
  .port = "80";
  }
  </code></pre>
  
  <p>2) I have a simple PHP file that has only these two line:</p>
  
  <pre><code>session_start();
  echo time();
  </code></pre>
  
  <p>3) 
  When I call this page it correctly does not cache
  as I have not added in the required vcl rules</p>
  
  <p>4)</p>
  
  <p>So as per my understanding of the documentation I add
  in these two rules</p>
  
  <pre><code>sub vcl_recv {
  unset req.http.Cookie;
  return (lookup);
  }
  
  sub vcl_fetch {
  unset beresp.http.Set-Cookie;
  return(deliver);
  }
  </code></pre>
  
  <p>5)
  The PHP page still will not cache.
  I can see the <code>Set-Cookie</code> header has been
  removed as I'm using FireBug in FireFox.</p>
  
  <p>It's only if I add this to sub vcl_fetch
  that the PHP will cache:</p>
  
  <pre><code>set beresp.ttl = 24h;
  </code></pre>
  
  <p>My question is is this correct?</p>
  
  <p>I didn't think I would need to alter the ttl
  of the backend response. I thought just unsetting
  cookies in and out would force PHP w/ session to cache.</p>
  
  <p>My complete default vcl is:</p>
  
  <pre><code>backend default {
  .host = "127.0.0.1";
  .port = "80";
  }
  
  sub vcl_recv {
  unset req.http.Cookie;
  return (lookup);
  }
  
  sub vcl_fetch {
  unset beresp.http.Set-Cookie;
  set beresp.ttl = 24h;
  return(deliver);
  }
  </code></pre>
  
  <p>My start up command is:</p>
  
  <pre><code>varnishd -f /etc/varnish/default.vcl -s malloc,128M -T 127.0.0.1:2000 -a 0.0.0.0:8080
  </code></pre>
  
  <p>The URL I am calling is:</p>
  
  <pre><code>http://vbox.local:8080/varnish-tests/index.php
  </code></pre>
  
  <p>My index.php file has only:</p>
  
  <pre><code>&lt;?php 
  session_start();
  echo time();
  </code></pre>
  
  <p>I would like to ask the community if this looks correct
  or if I am wrong. Essentially I'm just unsure why I had
  to add the beresp.ttl = 24h to finally have the page cache
  in varnish.</p>
  
  <p>I thought I would not need this.</p>
  
  <p>Any advise much appreciated. </p>
  
  <p>Thank you!</p>
  
  <p>Kind regards.</p>