Telewa Telewa - 8 days ago 6
Apache Configuration Question

When is index.php in wordpress executed?

I have this code in the root index.php of a wordpress installation

define('WP_USE_THEMES', true);

file_put_contents("/tmp/test.php", print_r($_SERVER, true));

/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );


I notice that if i comment out the last line so that it becomes only

define('WP_USE_THEMES', true);

file_put_contents("/tmp/test.php", print_r($_SERVER, true));


the array printed in /tmp/test.php is defferent!.
The array has values such as

[HTTP_COOKIE] => pll_language=en
[REQUEST_URI] => /site_front_page/


Why is that? and yet the code that should write to the file /tmp/test.php is placed before the code

require( dirname( __FILE__ ) . '/wp-blog-header.php' );


in both cases?

EDIT: 1
The REQUEST_URI for example should be just

[REQUEST_URI] => /

Answer

It seems there are multiple requests to index.php. The very first time a request is made to the site root(before any redirection is done) the

  [REQUEST_URI] => /

The array is written to the file just OK. However, after wordpress does the redirection in the next piece of code:

/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );

and decides what the actual home url is, then a second request is made to the site but now to the url:

[REQUEST_URI] => /site_front_page/

At this point, we overwrite the very first array that was written to /tmp/test.php.

That's why.