Check if the X-Sendfile header is working

I am looking for a way to confirm whether the X-Sendfile processes requests sent to the web server correctly using a script (PHP). Images are served correctly, but I thought I would see the headline in curl requests.

$ curl -I http://blog2.stageserver.net/wp-includes/ms-files.php?file=/2011/05/amos-lee-feature.jpg HTTP/1.1 200 OK Date: Wed, 04 Jan 2012 17:19:45 GMT Server: Cherokee/1.2.100 (Arch Linux) ETag: "4dd2e306=9da0" Last-Modified: Tue, 17 May 2011 21:05:10 GMT Content-Type: image/jpeg Content-Length: 40352 X-Powered-By: PHP/5.3.8 Content-Disposition: inline; filename="amos-lee-feature.jpg" 

Configuration

Cherokee 1.2.100 with PHP-FPM 5.3.8 in FastCGI:
cherokee.conf: vserver!20!rule!500!handler!xsendfile = 1
(Install using vServer> Behavior> php Extensions> Handler: Allow X-Sendfile [check Enabled])

Wordpress / WPMU 3.3.1 Network :
define('WPMU_SENDFILE',true); set in wp-config.php as follows before wp-settings.php . This will run the following code, which will be executed in WP wp-includes / ms-files.php: 50 serves files for a specific blog:

 header( 'X-Sendfile: ' . $file ); exit; 

I confirmed that the above snippet is accomplished by adding an extra header to delete immediately before calling exit(); . This Content-Disposition is present with the curl results above, and not initially in ms-files.php code. Added code:
header('Content-Disposition: inline; filename="'.basename($file).'"');


Study

I have:

  • Reboot the php-fpm / cherokee daemons after making configuration changes.
  • I tried a few tricks in the comments in php.net/readfile and replaced the simple header in ms-files.php more complete code from the examples.
    • php.net/manual/en/function.readfile.php
    • www.jasny.net/articles/how-i-php-x-sendfile/
    • * codeutopia.net/blog/2009/03/06/sending files-better-apache-mod_xsendfile-and-php / *
  • Confirmed support [cherokee support] [5] and tested [with and without] [6] compression, although I do not think that this is applicable, since my images work correctly. I also found a suspiciously similar problem from the lighttpd post.
    • * cherokee-project.com/DOC/other_goodies.html *
    • code.google.com/p/cherokee/issues/detail?id=1228
    • webdevrefinery.com/forums/topic/4761-x-sendfile/
  • An ad unit is found here on SO, which may indicate that the header is being split
    • stackoverflow.com/questions/7296642/django-understanding-x-sendfile
  • It is tested that the headers above are compatible with curl, wget, Firefox, Chrome and web-sniffer.net.
  • Learned that I can not publish more than two links due to lack of reputation.

Questions

  • Will the X-Sendfile be present in the headers when it works correctly or is stripped?
  • Can I use access logs to determine if the X-Sendfile working?

I am looking for general troubleshooting tips or information here that is not necessarily specific to PHP / Cherokee.

Update

I found a suitable way to validate X-Sendfile or X-Accel-Redirect in a test or sandbox: disable X-Sendfile and check the headers.

With enabled disabling of the X-Sendfile in Cherokee:

 $ curl -I http://blog2.stageserver.net/wp-includes/ms-files.php?file=/2011/05/amos-lee-feature.jpg HTTP/1.1 200 OK Date: Fri, 06 Jan 2012 15:34:49 GMT Server: Cherokee/1.2.101 (Ubuntu) X-Powered-By: PHP/5.3.6-13ubuntu3.3 Content-Type: image/jpeg X-Sendfile: /srv/http/wordpress/wp-content/blogs.dir/2/files/2011/05/amos-lee-feature.jpg Content-Length: 40352 

The image does not load in browsers, but you can see that the title is present. After enabling Enable X-Sendfile again, the image is loaded and you can be sure that the X-Sendfile is working.

+7
source share
3 answers

According to the source on github, the X-Sendfile headers will be deleted.

If I combine the file correctly, it will only log successfully if it was compiled in debug mode.

0
source

You can check the memory usage for sending large files with and without xsendfile.

0
source

They are deleted, simply because the presence of this data will prevent one of the reasons for its use, namely the presence of a file serviced without a recipient, knowing the location of the file that will be serviced.

0
source

All Articles