wp-rocket
wp-rocket copied to clipboard
Adding exclusive lock (to avoid unnecessary CPU usage) when WP Rocket knows a page can be cached?
Hello!
I am just wondering why "maybe_process_buffer()" doen't use an exclusive lock when it detects that a page can be put in cache.
For instance, if a page is not in cache and there are 10 simultaneous requests to it within a short laps of time, then WP Rocket will let PHP render this page from scratch many times until a cached version is written and detected.
Is it intended? (Maybe yes, I am unaware of possible gotchas)
In Varnish, this process is called "request coalescing": fetch/process a resource once (lock) then deliver it to any pending requests.
Have a great day!
Hello @trendymail and thank you for starting the discussion.
@Tabrisrp what would be your opinion here? 🤔
It's an interesting idea, I don't know if it's something that can be achieved through PHP though.
AFAIK, mkdir() is atomic (except over NFS, SSHFS, other?) so this function could be used to set/get an exclusive lock in PHP.
Not sure that PHP flock() is thread safe.