Introduction #
The Page Cache Delivery Method setting in Solid Performance controls how cached pages are served to site visitors. This document explains why the setting matters, how it can improve page load times, and what to expect when switching between the available methods.
What Is the Page Cache Delivery Setting? #
This setting determines whether cached pages are delivered via:
- htaccess (Apache & Litespeed servers only)
- PHP
- Nginx (Experienced system administrators only)
When the setting is set to htaccess, Apache’s built-in rewrite rules (stored in a file called .htaccess) serve cached pages without invoking PHP. If Apache is not detected or the hosting environment does not allow .htaccess modifications, the PHP method delivers cached content instead as a fallback.
Why Change the Page Cache Delivery Method? #
Caching is designed to load pages faster by storing a pre-built version of each page. The Page Cache Delivery Method helps ensure those cached pages reach visitors with minimal delay.
Bypass PHP for Better Performance (If Using Apache) #
Apache servers can handle redirection and rewrites directly through .htaccess. This approach often leads to faster response times because it avoids the extra overhead of processing each request through PHP.
- htaccess: Leverages Apache’s native rewrite system to quickly serve cached files.
- PHP: Uses server-side scripting to deliver cached pages, which can be slightly slower because it still relies on PHP to handle each request.
- Nginx: Requires manual configuration by an experienced system administrator. This method involves adding specific rewrite rules to your Nginx server block configuration to serve cached pages directly, bypassing PHP. Follow the steps outlined below to configure Nginx for Solid Performance page caching.
Default Behavior #
Starting with version 1.6.0, Solid Performance detects whether Apache is used on the server. If Apache is found, htaccess is selected by default. Otherwise, the default is PHP.
Examples #
Here are a few examples of why you would choose each setting.
Using htaccess #
When a site is hosted on an Apache server, enabling htaccess in the Page Cache Delivery Method allows Apache to serve cached pages directly. This approach can significantly reduce server resource usage by avoiding PHP altogether. If .htaccess is removed or the server does not allow .htaccess modifications, it may be necessary to switch to PHP to ensure the cache still functions.
Using PHP #
For hosting environments without Apache, or in cases where .htaccess is restricted, PHP remains a reliable method for serving cached pages. Although PHP caching introduces slightly more overhead, it still reduces the time needed to generate pages from scratch while ensuring that any necessary HTTP headers are delivered appropriately.
Note: If a URL requires special HTTP Response headers to be sent with a cached request, that URL should either be excluded from caching or .htaccess caching should be disabled in favor of the PHP fallback.
Using Nginx #
Note: This configuration requires root access and should only be carried out by experienced system administrators.
The nginx option will not be available if we do not detect the Nginx webserver.
Nginx servers require manual configuration to implement page caching similar to Apache’s .htaccess method. To enable page caching on Nginx, you need to add specific rewrite rules to your server block configuration within your Nginx virtual host configuration file.
Follow these steps to configure Nginx for Solid Performance page caching:
- Obtain the Nginx Configuration Snippet:
- Navigate to the Solid Performance settings page > Advanced Tab where the Page Cache Delivery Method is configured.
- Select the nginx option from the drop down and press save.
- Locate the Nginx configuration snippet and click the “Copy to Clipboard” icon. This snippet contains the include path to the generated swpsp-nginx.conf file.
- Include the Configuration in Your Server Block:
- Open your virtual host configuration file for your site.
- Within the server{} block for your website, paste the directive from step 1.
Here’s an example of how your vhost server{} block might look:
server {
listen 80;
server_name yourdomain.com;
root /var/www/yourdomain.com/html;
index index.php;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Include the Solid Performance cache configuration.
include /var/www/yourdomain.com/html/swpsp-nginx.conf;
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
}
Important:
- Replace /var/www/yourdomain.com/html/swpsp-nginx.conf; with the actual path copied from the Settings page.
- If your existing configuration has a location / {} block, ensure to remove it as the Solid Performance rules provide this.
- Test the configuration by running sudo nginx -t from the remote shell.
- Restart Nginx for the changes to take effect: sudo systemctl restart nginx.
Note: Any changes to the swpsp-nginx.conf file require you to reload your Nginx configuration. Test with sudo nginx -t and reload with sudo systemctl reload nginx.
Do not directly modify this file, if you need to customize it, utilize the solidwp/performance/nginx/rules or the solidwp/performance/nginx/bypass/rules (bypass) WordPress filter and regenerate the configuration.
Conclusion and Next Steps #
Optimizing how cached pages are delivered can significantly affect load times and overall site performance. Selecting the htaccess option on Apache servers often yields the best results, while the PHP option ensures that caching still works in other environments.
Have questions or run into issues? Don’t hesitate to contact support!
