psr7-cache icon indicating copy to clipboard operation
psr7-cache copied to clipboard

Warn about PHP sessions in documentation

Open kAlvaro opened this issue 5 years ago • 1 comments

This library works like a charm but there was an issue that kept me hitting a wall. It'd be nice if it was mentioned somewhere in the README file.

PHP session handler generates its own headers. The exact ones depend on the session.cache_limiter directive. Its default value is nocache and that means you get:

Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache

This interferes completely with \Micheh\Cache\CacheUtil::withCache(). Only Cache-Control finally gets the value set by this method. It's also not obvious at first sight because these extra headers are set by PHP core and are invisible for PSR-7 implementations (at least the one I'm using).

It's not necessarily the library's fault but it can lead you to wonder why it isn't working. If you want to cache responses from session based applications you need to set session.cache_limiter to something that's not the default, e.g.:

ini_set('session.cache_limiter', 'public');

Reference can be found at session_cache_limiter() manual page.

kAlvaro avatar Aug 15 '19 11:08 kAlvaro

This is actually quite a big deal. I'm not really using this library at the moment (although I think I will) but I came across this post which solved my issue with a PSR-7 lib not properly setting Cache-Control because I have sessions started. Thank you for pointing this out.

zkwbbr avatar May 07 '20 00:05 zkwbbr