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

XF 1.4 Slow response from XenForo_FileOutput::output

We're troubleshooting some slow site transactions on our site. We've see requests to attachments from index.php that are loading slowly.

NewRelic shows a big lag in response from XenForo_FileOutput, where it took 12,600 ms for this function to respond.

Slowest components Count Duration %
XenForo_FileOutput::eek:utput 1 12,600 ms 100%
Memcache get 27 16 ms 0%
/index.php 1 5 ms 0%
XenForo_Model_DataRegistry::getMulti 1 4 ms 0%
XenForo_FrontController::run 1 3 ms 0%
XenForo_Visitor::setup 1 3 ms 0%
Remainder 1 21 ms 0%
Total 12,700 ms 100%

I assume there's a lookup in the attachment table to find the attachment, then its requested from the file system. We are running on 2 load balanced servers, the app server load itself is low so I'm not sure why there would be such a lag with this function for some attachments but not all.

Anyone else experience this?


XenForo developer
Staff member
I'm not sure how this is logging, but that function actually reads a file and prints it out directly. That means it's actually running until the file is downloaded by the user or the connection is closed (there by closing PHP). If there's a slow connection, unless the result is being buffered outside of PHP, that function could well take some time to "complete". There isn't really a way around it unless you use something like X-Sendfile at the web server level.


Well-known member
There are some addons which add X-Sendfile support to XF, but it depends on the webserver being used to make sure you configure the right option.
So we've narrowed this down to most likely happening on slower devices like phones without a wifi connection, loading images from a connected pc seem to run quickly.

A few more questions:
1. When index.php runs and does its work to get an image is the database connection left open until XenForo_FileOutput::eek:utput returns? I see some queries involved in getting the image and tracking it in xf_attachment_view, I just wasn't sure when the connection gets closed. We are having some issues with too many open connections and wondering if this may be part of the cause.
2. Just reading up on X-Sendfile - would this help in the case of a device with a slower connection (and thus return / close the db connection faster)? It sounds like it cuts down on PHP processing and lets the file get served right from the file system via apache/ws but if is an image being loaded over a slow connection I assume it would still be kind of slow but still an improvement.


Well-known member
X-Sendfile allows php to setup permissions, redirects etc; and then delegate the actual file serving to the webserver which can do it without a database connections.
I'm definitely going to look more into X-Sendfile, thanks. My question is more about the db connection within Xenforo - is it opened when index.php starts and then closes when the all processing (including reading this file off the server) is done - or is the connection to the DB opened when a query is run and then closed once the results are retrieved?