Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have enabled the mod_cache and mod_disk_cache Apache modules, to enable caching of dynamically generated images form a PHP script (based on width and height parameters).

Everything works fine (Apache caches the files) whenever I supply small width and height parameters to my PHP script. However when I supply larger parameters, and as the image size gets bigger (above around 50k) Apache is not caching the response anymore. In that case Apache does create a directory in the /var/cache/apache/mod_disk_cache but the directory is empty (it does not contain the .header and .data files).

I have tried to set the CacheMaxFileSize directive but it did not seem to work (I tried setting it a a large value (2000000) in the disk_cache.conf file but it did not seem to have any effect and setting the directive in the site configuration file disabled all caching - caching of small files stopped working).

Has anybody encountered something similar and knows how to solve it?

Server is running Ubuntu 12.04 with Apache 2.2.22

Here is my config:


<IfModule mod_disk_cache.c>
# cache cleaning is done by htcacheclean, which can be configured in
# /etc/default/apache2
# For further information, see the comments in that file, 
# /usr/share/doc/apache2.2-common/README.Debian, and the htcacheclean(8)
# man page.

    # This path must be the same as the one in /etc/default/apache2

    CacheRoot /var/cache/apache2/mod_disk_cache

    # This will also cache local documents. It usually makes more sense to
    # put this into the configuration for just one virtual host.

    CacheDirLevels 2
    CacheDirLength 1
    CacheIgnoreCacheControl On
    CacheIgnoreURLSessionIdentifiers jsessionid
    CacheIgnoreURLSessionIdentifiers PHPSESSID
    CacheIgnoreHeaders Set-Cookie
    CacheMaxFileSize 2000000



<VirtualHost *:80>
    DocumentRoot /var/www/

    <Directory />
        Options None
        AllowOverride None
        Order allow,deny
        Deny from all

    <Directory /var/www/>
        AllowOverride All

    <Directory /var/www/>
        Options FollowSymlinks
        Order allow,deny
        Allow from all

    <IfModule mod_disk_cache.c>
        CacheEnable disk /cached/

    ErrorLog ${APACHE_LOG_DIR}/
    LogLevel debug
    CustomLog ${APACHE_LOG_DIR}/ combined

PHP image generation script /var/www/


//Generate Imagick image based on provided width and height

header("Content-Type: image/" . strtolower($image->getImageFormat()));
header("Content-Length: " . strlen($image));
header("Cache-Control: public, must-revalidate, max-age=2592000");
echo $image;

share|improve this question

The way a friend of mine has found is to force caching of whole file by using wget, simply:



wget -O /dev/null

without Range!

This will force apache to cache the whole file.

Than after that, accessing range in cached files is now possible...

( Sorry for the late answer: I've found this question by searching for this kind of solution. So after looking the running workaround, I post this ;)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.