rtCamp / nginx-helper

Nginx Helper for WordPress caching, permalinks & efficient file handling in multisite
https://wordpress.org/plugins/nginx-helper/
224 stars 117 forks source link

Offload "Purge Entire Cache" request to cron service/schedule #331

Open abdusfauzi opened 3 months ago

abdusfauzi commented 3 months ago

I have a multisite blog and the cache is quite large due to the number of traffic and contents.

I have been facing the error in Nginx as below:

2024/03/31 12:36:26 [error] 2028878#2028878: *201901 upstream sent too big header while reading response header from upstream, client: 113.211.208.12, server: domain.com, request: "GET /wp/wp-admin/network/settings.php?page=nginx&nginx_helper_action=purge&nginx_helper_urls=all&_wpnonce=08e9fbc39c HTTP/2.0", upstream: "fastcgi://unix:/run/php/php8.2-fpm.sock:", host: "domain.com", referrer: "https://domain.com/wp/wp-admin/network/settings.php?page=nginx&nginx_helper_action=purge&nginx_helper_urls=all&_wpnonce=08e9fbc39c"

And changing the Nginx fastcgi_buffers and fastcgi_buffer_size does not seems to solve the issue. Hence, I went deep into the plugin to see where does this came from.

Apparently, on the request to "Purge Entire Cache", the GET request execute the purge_all method in FastCGI_Purger class. Then, in that method is runs $this->unlink_recursive(). This seems to produce huge response buffer.

I decided to offload that process to Cron, using wp_schedule_single_event.