Php 如何将缓存控制过期标头添加到图像?

Php 如何将缓存控制过期标头添加到图像?,php,zend-framework,cache-control,zend-cache,Php,Zend Framework,Cache Control,Zend Cache,我正在努力加快我网站的速度。YSlow提醒我,我的图像缺少标题。但是如何在图像上应用这样的标题呢 我的应用程序基于zend框架。图像和图像都存储在文件夹中,我如何才能为它们设置expires头?如果您使用apache,在httpd.conf中,您可以执行以下操作: LoadModule expires_module modules/mod_expires.so ExpiresActive On ExpiresDefault "access plus 300 seconds" <Direct

我正在努力加快我网站的速度。YSlow提醒我,我的图像缺少标题。但是如何在图像上应用这样的标题呢


我的应用程序基于zend框架。图像和图像都存储在文件夹中,我如何才能为它们设置expires头?

如果您使用apache,在
httpd.conf
中,您可以执行以下操作:

LoadModule expires_module modules/mod_expires.so
ExpiresActive On
ExpiresDefault "access plus 300 seconds"
<Directory "/myProject/webResources">
    Options FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
    ExpiresByType image/gif "access plus 1 day"
    ExpiresByType image/jpg "access plus 1 day"
    ExpiresByType image/png "access plus 1 day"
    ExpiresByType application/x-shockwave-flash "access plus 1 day"
</Directory>
LoadModule expires\u modules/mod\u expires.so
过期于
ExpiresDefault“访问加300秒”
选项如下符号链接多视图
允许超越所有
命令允许,拒绝
通融
ExpiresByType image/gif“访问加1天”
ExpiresByType图像/jpg“访问加1天”
ExpiresByType图像/png“访问加1天”
过期按类型应用程序/x-shockwave-flash“访问加1天”

如果您使用的是apache,那么在
httpd.conf
中,您可以执行以下操作:

LoadModule expires_module modules/mod_expires.so
ExpiresActive On
ExpiresDefault "access plus 300 seconds"
<Directory "/myProject/webResources">
    Options FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
    ExpiresByType image/gif "access plus 1 day"
    ExpiresByType image/jpg "access plus 1 day"
    ExpiresByType image/png "access plus 1 day"
    ExpiresByType application/x-shockwave-flash "access plus 1 day"
</Directory>
LoadModule expires\u modules/mod\u expires.so
过期于
ExpiresDefault“访问加300秒”
选项如下符号链接多视图
允许超越所有
命令允许,拒绝
通融
ExpiresByType image/gif“访问加1天”
ExpiresByType图像/jpg“访问加1天”
ExpiresByType图像/png“访问加1天”
过期按类型应用程序/x-shockwave-flash“访问加1天”

我昨天遇到了同样的问题

  • 确保在生成图像的操作中设置了正确的标题
  • 您必须将带有“内容类型”的Memory_头添加到FrontInOptions中,为了提高性能,还必须添加“缓存控制”和您想要设置的任何头
  • 因此,Zend_Cache_Frontend_页面的示例如下所示:

    $frontendOptions = array(
       'lifetime' => 7200,
       'debug_header' => true, // for debugging
       'regexps' => array(
           // cache the whole IndexController
           '^/$' => array('cache' => true),
    
           // cache the whole IndexController
           '^/index/' => array('cache' => true),
    
           // we don't cache the ArticleController...
           '^/article/' => array('cache' => false),
    
           // ... but we cache the "view" action of this ArticleController
           '^/article/view/' => array(
               'cache' => true,
    
               // and we cache even there are some variables in $_POST
               'cache_with_post_variables' => true,
    
               // but the cache will be dependent on the $_POST array
               'make_id_with_post_variables' => true
           )
       ),
        'memorize_headers' => array(
            'Content-Type',
            'Cache-Control',
            'Expires',
            'Pragma',
       )
    );
    
    $backendOptions = array(
        'cache_dir' => '/tmp/'
    );
    
    // getting a Zend_Cache_Frontend_Page object
    $cache = Zend_Cache::factory('Page',
                                 'File',
                                 $frontendOptions,
                                 $backendOptions);
    
    $cache->start();
    

    我昨天遇到了同样的问题

  • 确保在生成图像的操作中设置了正确的标题
  • 您必须将带有“内容类型”的Memory_头添加到FrontInOptions中,为了提高性能,还必须添加“缓存控制”和您想要设置的任何头
  • 因此,Zend_Cache_Frontend_页面的示例如下所示:

    $frontendOptions = array(
       'lifetime' => 7200,
       'debug_header' => true, // for debugging
       'regexps' => array(
           // cache the whole IndexController
           '^/$' => array('cache' => true),
    
           // cache the whole IndexController
           '^/index/' => array('cache' => true),
    
           // we don't cache the ArticleController...
           '^/article/' => array('cache' => false),
    
           // ... but we cache the "view" action of this ArticleController
           '^/article/view/' => array(
               'cache' => true,
    
               // and we cache even there are some variables in $_POST
               'cache_with_post_variables' => true,
    
               // but the cache will be dependent on the $_POST array
               'make_id_with_post_variables' => true
           )
       ),
        'memorize_headers' => array(
            'Content-Type',
            'Cache-Control',
            'Expires',
            'Pragma',
       )
    );
    
    $backendOptions = array(
        'cache_dir' => '/tmp/'
    );
    
    // getting a Zend_Cache_Frontend_Page object
    $cache = Zend_Cache::factory('Page',
                                 'File',
                                 $frontendOptions,
                                 $backendOptions);
    
    $cache->start();