The Fast Display Images feature is designed to improve performance and reduce memory usage in XenForo by bypassing the built-in PHP image handling. Instead of letting XenForo process and serve image attachments, this method uses either X-Sendfile (Apache) or X-Accel-Redirect (Nginx) to deliver files directly from the web server.
This approach is particularly useful for forums with large image attachments, as it lowers PHP’s workload and allows the web server to efficiently stream files to users.
Important note, when using this method, everyone can see all the images on the forum (except Direct Message image atachments). If your forum needs image protection, you should not use it.
For image attachments of Direct Messages (conversations), it will add a security step to check the user (user_id) to ensure that only members of the conversation can view the image files.
Key Benefits:
- Lower RAM usage: PHP does not load and buffer images.
- Better performance: Images are streamed directly by the web server.
- Scalable: Handles large files with minimal server overhead.
- Flexible: Supports both Apache (X-Sendfile) and Nginx (X-Accel-Redirect).
- A custom cache.php script handles image requests.
- The script checks the attachment and, if available, sends headers for X-Sendfile or X-Accel-Redirect.
- The web server delivers the file directly, skipping PHP’s memory-intensive file reading.
1. Download and Configure cache.php
- Download the provided cache.php file. (XenVn Setting -> Attachments -> Attachment Download Acceleration -> Fast Display Images)
- Open the file and configure:
- ACCELERATION -> Set to apache (Apache X-Sendfile) or nginx (Nginx X-Accel-Redirect).
- NGINX_ALIAS -> (Only for Nginx) Define the internal alias path if required.
- EXTERNAL_FOLDER -> Path to External Storage Folder if you are using External Storage Connection feature
- Upload cache.php to the XenForo root directory.
Adjust:define('CACHE', ['image' => true, 'css' => true]);to select working modes. For example:
define('CACHE', ['image' => true, 'css' => true]);-> Default. Fast Display Images and Fast CSS Loading for XenForo.
define('CACHE', ['image' => true, 'css' => false]);-> Only Fast Display Images for XenForo.
define('CACHE', ['image' => false, 'css' => true]);-> Only Fast CSS Loading for XenForo.
To view X-Memory-Usage header information, set:
define('DEBUG', true);
2. Update .htaccess in XenForo Root (apache server)
Insert the following rules above the existing
RewriteCond %{REQUEST_FILENAME} -f [OR] line:
Code:
You must log in to view
(4 lines)
Configuring Apache with X-Sendfile
Step 1: Install the X-Sendfile Module
On Debian/Ubuntu:
Code:
You must log in to view
(1 lines)
Step 2: Enable the Module
Code:
You must log in to view
(1 lines)
Step 3: Configure Apache Virtual Host
Edit your XenForo site’s Apache configuration (e.g., /etc/apache2/sites-available/000-default.conf):
Code:
You must log in to view
(20 lines)
Restart Apache:
Code:
You must log in to view
(1 lines)
Step 4: Adjust cache.php
Set:
PHP:
You must log in to view
(1 lines)
Configuring Nginx with X-Accel-Redirect
Step 1: Define an Internal Alias
Edit your Nginx server block (e.g., /etc/nginx/sites-available/xenforo):
Code:
You must log in to view
(21 lines)
Step 2: Adjust cache.php
Set:
PHP:
You must log in to view
(2 lines)
Step 3: Restart Nginx
Code:
You must log in to view
(1 lines)
If your server does not support X-Sendfile / X-Accel-Redirect, you can use PHP (Chunked Streaming), set:
Code:
You must log in to view
(1 lines)
The Fast Display Images feature is a lightweight and powerful optimization for XenForo forums. By integrating X-Sendfile or X-Accel-Redirect, you offload image delivery to the web server, saving RAM and CPU while improving user experience.
This setup is highly recommended for busy forums with heavy image usage.
Results:
Last edited: