File change on a LAMP development server not taken into account

apache-2.2cachevirtualbox

I set up a small LAMP virtual machine for PHP development.

It works fine, excepted that when an image which has already been served is modified on disk, then requested again, the "old" image is still being served (I get a 304 Not Modified answer from apache2). This caching behaviour is desirable on a server, but is a pain on a development environment where files are frequently edited.

The only (inconvenient) ways I found to access the new file content are:

  1. rebooting the VM,
  2. or issuing sync; echo 3 > /proc/sys/vm/drop_caches

Is there an apache directive I can use to ensure that apache will check if a file has changed on disk each time it is requested?

Update : Loaded Apache modules:

# apache2ctl -t -D DUMP_MODULES
Loaded Modules:
 core_module (static)
 log_config_module (static)
 logio_module (static)
 mpm_prefork_module (static)
 http_module (static)
 so_module (static)
 alias_module (shared)
 auth_basic_module (shared)
 authn_file_module (shared)
 authz_default_module (shared)
 authz_groupfile_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 cgi_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 mime_module (shared)
 negotiation_module (shared)
 php5_module (shared)
 setenvif_module (shared)
 status_module (shared)
Syntax OK

Edit: actually, my DocumentRoot is stored on a shared VirtualBox folder. It seems like when a file is overwritten, the virtualbox module does not notify linux to invalidate its cache. Hence the counterintuitive behavior. When I perform the same overwriting operation on a "regular" linux directory, no such thing happen.

Best Answer

OK, I found the explanation on a VirtualBox ticket: the "sendfile" optimization seems not to be implemented by the vboxsf module.

Until this issue is fixed, a workaround is to use this Apache directive :

EnableSendfile Off 

Using this, server-side images changes are taken into account immediately.