John Davidson

Does WordPress trigger index.php when the page is cached?

0 comments
Message:


All pages on my site are cached using the WP Rocket plugin, and everybody is telling me that the root index.php is not triggered when a page is cached.


I went ahead and added this piece of code to my root index.php to track its executions:


error_log( date('[ Y-m-d H:i:s ] ', $_SERVER['REQUEST_TIME'] ) . $_SERVER['REQUEST_URI'] ."\n", 3, dirname( __FILE__ ) . "/index.php.log" );

I checked the log and indeed the index.php seems to not trigger on cached pages.


What I don't understand is that online guides about WordPress loading sequence say that index.php is the very first thing that gets executed when you visit a site. It loads wp-blog-header.php, then wp-load.php sets up the WordPress environment, etc.


https://medium.com/@dendeffe/wordpress-loading-sequence-a-guided-tour-e077c7dbd119
https://www.mikeinmonospace.com/wordpress-internals-loading-sequence/


So what am I missing? Why isn't index.php triggered when the page is cached? Is there anything triggered before index.php that loads the cached page?



My Answer:
When a page is cached, the cached version of the page is served to visitors instead of the server having to generate the page dynamically. This means that the server does not need to go through the entire WordPress loading sequence, including triggering the index.php file.

Instead, when a cached page is served, the server simply retrieves the cached HTML file and sends it to the visitor's browser. This bypasses the need for WordPress to load and process the PHP files, including index.php.

So, in the case of cached pages, index.php is not triggered because the server is serving a static HTML file instead of dynamically generating the page using PHP. This is why you are not seeing the code in your index.php file being executed when a cached page is served.

Rate this post

5 of 5 based on 8820 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us