Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

abdusfauzi
Copy link

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.

Introduce a hook "nginx_helper_unlink_recursive" to run a function "run_cron_unlink_recursive()" which will run the "unlink_recursive()" function and delete all directory
Refactor purge_all from running the `$this->unlink_recursive()` immediately, to being scheduled to offload this task to cron service and run as soon as possible.

This to avoid the overhead of buffering the response immediately to Nginx and trigger the error "upstream sent too big header while reading response header from upstream"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant