• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XAR - Attachment [Deleted]

Xon

Well-known member
#1
Xon submitted a new resource:

XAR - Attachment - Enables the use of Nginx's X-Accel-Redirect for attachment serving

Enables the use of Nginx's X-Accel-Redirect header feature for attachment serving.

This permits XenForo to-do validation and authentication, and offload the actual file serving to Nginx. This feature is not particularly well documented, but some info found here.

As XenForo_FileOutput is not extensible, this addon reimplements:
  • XenForo_ViewAdmin_Attachment_View
  • XenForo_ViewPublic_Attachment_View

This addon assumes the...
Read more about this resource...
 

Xon

Well-known member
#5
You can actually extend XenForo_FileOutput by porting into front_controller_post_view. You can look into this resource on how it was done: https://xenforo.com/community/resources/goodfornothing-fileoutput-enhancement.3602/
I'll have a look at that.

This can actually even proxy the requst to another server. Cool add-on!
I need to tweak it a bit, as I need to define a "internalDataUri" to properly handle if internal_data isn't in webroot(such as if you are using stream filters). The alias isn't enough.

XenForo delegates file serving of attachments to nginx, rather than an expensive php worker being tied up for the duration of the entire request.
 

Xon

Well-known member
#6
Xon updated XAR - Attachment with a new update entry:

Support for internal_data being outside the webroot

Support for internal_data being outside the webroot.

If the internal_data directory is outside the webroot, or you are using php stream filters you will probably need to set the 'internalDataUrl' entry.

In config.php add:
Code:
config['internalDataUrl'] = '/internal_data';
In your nginx config add something like:
Code:
location /internal_data {
  internal;
  alias /path/to/internal_data;
}
Read the rest of this update entry...
 
Last edited:

Xon

Well-known member
#8
This is required on my config.php?
Code:
config['internalDataUrl'] = '/internal_data';
Only if you are using php stream filters, or have moved the internal data directory outside the webroot.

By default, XenForo puts that folder in the webroot and you need to explicitly move it.
 

RoldanLT

Well-known member
#10
And how can I verify it's working as intended? :)
I only allow 2mb max filesize attachment upload, Do I still have benefits on this?
Thanks!
 

Xon

Well-known member
#11
This I don't understand correctly :)
php stream filters basically let you access some arbitrary URI as if it was a file. It's an advanced technique which has it's uses.

And how can I verify it's working as intended? :)
I only allow 2mb max filesize attachment upload, Do I still have benefits on this?
Thanks!
The easiest way is to check the response headers via your browser debug tools, when viewing an attachment,

The etag header will be an alphanumeric string rather than a simple integer.

For example,

Before:
Etag "1419835168"
After:
Etag "54a0f720-2f90"
 

Xon

Well-known member
#13
By the way, after implementing this, my Cpu usage cuts off. Thanks!
I don't expect it would be that big a difference, but it depends on how heavily you use attachments.

How XenForo sends attachments is ok. But it is limited, by the fact that the better solutions are webserver specific.

For example; @Mr. Goodie2Shoes addon that was linked earlier is vastly more complex than mine. But because downloads are delegated to the webserver, resumable multi-part downloading is provided for free without tying up expensive php processes for each client connection.
 

Xon

Well-known member
#15
@Xon, Why you copy/paste original XenForo methods and not call parent method?
I'm actually planning on going back and cutting out all the redundant header setting which isn't required when using nginx's X-Accel-Redirect header.

Fundamentally, I'm only planning on supporting nginx and to fall back on the original method the best solution is to disable the addon.

You can look in my implementation (part of last version CMF_Core)
https://github.com/Yoskaldyr/cmf_co...y/CMF/Core/ViewPublic/Attachment/View.php#L12
or in separate version of the addon written in 2010 year (attachment in the forum post):
http://www.xf-russia.ru/forum/threa...lozhenij-esli-ustanovlen-nginx.502/#post-5971
Wish I found that earlier, would have saved some effort.
 

D.O.A.

Well-known member
#18

D.O.A.

Well-known member
#20
Some days ago I've update code for better compatibility with other add-ons. Right now local file path gets from XenForo_FileOutput object (not from settings).
You can modify your old code like new one from CMF_Core_ViewPublic_Attachment_View (github link to code and to commit)
Thanks again, I have 200,000 image attachments it made a difference the day I first installed in 2010. My CPU thanks you!