X-Sendfile support ?

X-Sendfile support ?

by Daniel Neis Araujo -
Number of replies: 8
Picture of Core developers Picture of Plugin developers Picture of Translators

Hello,

 

is there any plans to add support fo X-Sendfile in Moodle?

Here is some reference about the support of it in nginx, lighttpd and even iis.

http://wiki.nginx.org/XSendfile
https://tn123.org/mod_xsendfile/
http://blog.lighttpd.net/articles/2006/07/02/x-sendfile
http://www.helicontech.com/ape/doc/mod_xsendfile.htm

Some people around the internet say that xsendfile is a big performance improvement serving static files ...

Just to note, according to this blog, ATutor has support to it since 2007...

 

Kind regards,

Daniel

Average of ratings: Useful (1)
In reply to Daniel Neis Araujo

Re: X-Sendfile support ?

by Gabriel Mazetto -

Just to clarify, the idea is to add support for it on file.php, so that file stream can be handled outside PHP (when X-Sendfile support is enabled)

In reply to Gabriel Mazetto

Re: X-Sendfile support ?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Sounds like it is worth investigating. Since pretty much all Moodle downloads are handled by one bit of code (file.php in 1.9, some function in lib/filelib.php in Moodle 2.0) it should be relatively easy to implement - if implementing it is possible.

However, something is much more likely to happen if you can 'Scratch your own itch' with this. If you can send us a patch that implements this, even if only as a proof-of-concept, we could see exactly what was involved in implementing and maintaining this.

In reply to Tim Hunt

Re: X-Sendfile support ?

by Dan Poltawski -
I'm interested in this. ( There appears to be an apache module for it too.)

Where does it improve performance? Just using less memory one frontend clients?

Having a not-too deep look, it appears it might be as simple as simply returning a header and not the stream:

header('X-Sendfile: /var/lib/moodle/filedir/31/70/31709f1b21a86c3b696a703d8636386c92108d95');

In reply to Dan Poltawski

Re: X-Sendfile support ?

by Gabriel Mazetto -

The gain is that you are not holding PHP process during file download  (as it's not streaming the file).

It works as Dan said, quoting from official website: "If it encounters the presence of such header it will discard all output and send the file specified by that header instead using Apache internals including all optimizations like caching-headers and sendfile or mmap if configured."

There are alternatives to all the major webservers as said by Daniel Neis.

In reply to Dan Poltawski

Re: X-Sendfile support ?

by Hubert Chathi -
It would just involve:
  • adding a configuration setting for whether to use X-Sendfile, and what the name of the header should be (there are at least two possibilities)
  • changing file.php to, when enabled, emit the X-Sendfile header and exit, instead of sending the file

Daniel, please put an issue into the tracker requesting this feature.

In reply to Daniel Neis Araujo

Re: X-Sendfile support ?

by Tomasz Muras -
Picture of Core developers Picture of Plugin developers Picture of Plugins guardians Picture of Translators

I have implemented it locally - it is pretty straight-forward, all right!

The next thing I've done was some testing and... I don't see pretty much any difference between using x-sendfile or not. I've tested downloads from small files to 140M file, testing with 5 concurent downloads - I have not noticed any speedups.

I will spend some more time on testing it - but have you seen any performance test that actually prove how much does this speed things up? The php script needs to be invoked anyway, so it's just helps with the streaming of the file. This is in Moodle handled by readfile() function which should be pretty efficient already. I imagine that this could save some memory on the server, as the PHP script ends earlier but those scripts don't take too much of a memory...


Tomasz Muras
Enovation Solutions