Question

I am running into a problem (on different hostings) and I cannot really change host settings so I am looking for PHP solution.

When I am sending response to browser (Symfony's HttpFoundation\Response) some headers are duplicate and they contradict themselves. Than browser will not cache them.

PHP code

    $response = new Response(
        $html,
        200,
        array(
            "content-type" => "text/html; charset=UTF-8",
        )
    );

    $response->setCache(array(
        'last_modified' => $page->getEditedAt(),
        'max_age'       => $staticCache,
        's_maxage'      => $staticCache,
        'private'       => false,
        'public'        => true,
    ));

Some of headers in browser

Cache-Control:max-age=1800, public, s-maxage=1800

Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0

Date:Tue, 01 Oct 2013 15:08:39 GMT

Expires:Thu, 19 Nov 1981 08:52:00 GMT

Pragma:no-cache

But my page should be public and cacheable. Where are the rest of headers set and how can i turn them off?

Was it helpful?

Solution

PHP is overriding your caching settings, that "Expires" date is very specific and included in the PHP source code. According to this stack overflow answer, it is the developer's birthday.

You can turn this off by changing the session.cache-limiter setting in your php.ini. The session_cache_limiter function page has more information about the possible values to set here. Try setting the value to public or to nothing and testing again.

You can see what the current value of the session.cache_limiter setting is with a small test page which echos the value:

<?php

echo(ini_get('session.cache_limiter'));

You said you are looking for a PHP solution, since you cannot edit host settings. You can change the value inside your code using the ini_set function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top