Php – Varnish doesn’t work with session on PHP

PHPsessionvarnish

I have got varnish installed on my server. I have a page on my site which i would like to get cached via Varnish.
With fresh varnish installation, I created a PHP page with some content in it. loaded the page. Varnish worked fine.

But as I added session_start() on first line of that page, The varnish cache stopped working.

What is the problem with Varnish and PHP session ? Can anyone help

Best Answer

I suggest you read the Varnish Book http://book.varnish-software.com/4.0/

It explains how Varnish and HTTP caches work.

You cannot have a session and cache the content at the same time.
You could configure varnish to do so, but it would be a different cache per different user (session) which makes the whole caching useless (depending on the website).