One of the powerful features of Fakoli is its ability to serve files from action handlers. This allows the ability to provide custom access control to resources such as documents and images, as well as providing a simple mechanism for serving and generating files on the fly, such as thumbnailed images or rendered PDF documents. One drawback of this mechanism is that the files are served from the PHP script, which has performance implications. Serving byte streams from PHP is not particularly efficient compared with serving files from Apache. It also locks up a PHP processing thread while the files are being downloaded. Fortunately there is a simple solution to all this, by virtue of the mod_xsendfile extension for Apache.
mod_xsendfile works by allowing the PHP (or other script) to return a file path to a static file in a custom HTTP response header. mod_xsendfile intercepts these headers and sends the specified file via Apache's regular file handling code, which is much more efficient at handling the output stream.
Fakoli will automatically detect and use mod_xsendfile when it is present, so all you have to do is configure the extension on your server. Here are the instructions:
On an Ubuntu server, this is a simple apt-get:
apt-get install libapache2-mod-xsendfile
The Apache configuration directives for mod_xsendfile were changed as of version 0.10, so you will need to know which version of mod_xsendfile you are working with (this will depend on the version of your Ubuntu distribution). Run the command:
dpkg -l | grep libapache2-mod-xsendfile
With a text editor, create the file /etc/apache2/mods-available/xsendfile.conf. If you are using a version of mod_xsendfile prior to 0.10, put this in the configuration file:
<Files *.php> XSendFile on XSendFileAllowAbove on </Files>
Otherwise, the configuration options are: