dongyixun0634 2013-10-01 15:18
浏览 70
已采纳

Symfony响应缓存控制标头重复

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?

  • 写回答

1条回答 默认 最新

  • douou5933 2013-11-01 00:24
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)