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 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。