I don't believe that it's currently well documented which is a shame, and something I'd like to improve when I have a few minutes. The current documentation that I've come across is all in config-dist.php (search for X-Sendfile).
The idea of the feature is to get the web server to serve files from moodledata rather than having it done using PHP. On the whole, this is a good thing for a number of reasons:
* php isn't particularly efficient at serving files in this way (byte-serving) - it doesn't cache files for starters (though your kernel should of course);
* while php is serving a file, it's unlikely to fork in an effective manner so you're also locking processes which could otherwise serve your users;
* your web server's primary aim is to serve files - it's designed for this and it is designed to do so in an extremely efficient manner. It's also likely to handle caching much more efficiently.
It's relatively easy to set up and at present there is support for:
* Apache2 - using the X-Sendfile header and mod_xsendfile (see https://tn123.org/mod_xsendfile/);
* nginx - using the X-Accel-Redirect header (see http://wiki.nginx.org/XSendfile); and
* lighttpd - using the X-LIGHTTPD-send-file header (see http://redmine.lighttpd.net/projects/lighttpd/wiki/X-LIGHTTPD-send-file).
We recently switched to serving the files for our main production site from moodledata (stored on NFS) to our nginx gateway server using X-Accel-Redirect. Before the switch, we had been experiencing some performance issues whereby our NFS server was sometimes being extremely slow to deliver files, which in turn caused PHP to wait whilst serving the file and we consequently saw high IO and a range of other issues affecting all users. Unfortunately the issues were usually extremely localised (affecting only some of five web nodes at a time) and short (10-30 seconds) which made them very difficult to track down accurately whilst still having a noticeable affect on end user experience.
We did make one additional change to our nginx configuration in addition to those detailed - we added configuration to ensure that our ETag headers were preserved correctly.
# Preserve the etag - X-Accel removes these
add_header Etag $upstream_http_etag;
After the switch we haven't suffered these issues any further and our performance on the whole is better. This hasn't moved the issue either - our gateway servers are seeing an increase on IO, but only very marginally. Unfortunately, I don't have any real metrics to demonstrate these improvements (sorry).
I've attached a copy of one of our munin graphs showing the change in IO before and after the switch from one of our web nodes.

Neat. By the way, we considered it here, but our server team don't want to set this up yet, so it's an option we'll hold in reserve in case needed.
One possible benefit might be reduced memory consumption. It can take a long time to serve a file if a user is on a slow connection or the file is large - say it takes half an hour to download a file, you're tying up a Moodle PHP process which probably has ~80MB of RAM (guessing - not sure if Moodle makes an effort to free this up when fileserving), whereas I bet Apache can do it on virtually nothing.
--sam
Looks useful!
I wonder if any Apache users have been able to get this working with Moodle? I've been able to download and install mod_xsendfile, but I'm having a slow moment when it comes to enabling it.
Any quick apache.conf snippets welcome!
--Ben
I am curious to know if you have any new insights and updates?
I not longer work Lancaster, but as far as I'm aware they are still using the X-Accel-Redirect to good affect, and I'm aware of other installations successfully using this without issue.
It's definitely something that I would recommend!
Andrew
What is the best way to test if x-senfile is sending files. Would it be in the POST event?
--
Daniel Nelson
UMass, Amherst
Hi Daniel,
X-Sendfile (and related) is used to off-load the server when serving those files <stored into>&<created by> Moodle e.g. a resource or an attachment in a forum or a bundle of CSS or JS files.
That being said, your site, after having configured X-Sendfile, must work the same as before: you'll see "just" the server load being lowered as the final (great) result. The load reduction percentage depends on both your instance (how many files stored) and your users concurrency.
HTH,
Matteo