Page 1 of 1

[SOLVED] strange 'REQUEST_URI page load delay

Posted: Sun Apr 03, 2011 11:11 pm
by stevestark5000
I am getting a strange 'REQUEST_URI page load delay with the following code in my php file. when i go to http://www.example.com it take between 3 to 22 seconds to load the page. Yet when I go to http://www.example.com/index.php it load in about 1.5 seconds.

the code checks to see if site is at root. if it is then change it to root/index.php which in turn changes the url. the code would work great if it was not for the delay in the page load.

can i have an explanation as to why i might be seeing a delay with the code or an alternative to the code would be nice.

I have this code in the user module of my cms. how i am thinking it takes a few seconds to load the site before it gets to my code. then when the code is ran it loads the site up the second time which creates the delay. could this code do this?

Code: Select all

if ($_SERVER['REQUEST_URI'] == "/") {
header("Location: ./index.php");
}

Re: strange 'REQUEST_URI page load delay

Posted: Mon Apr 04, 2011 1:01 am
by cpetercarter
header ("Location:....) is slow and inefficient. It sends a message from the server to the browser "Please ask for http://www.example.com/index.php". The browser receives the message and sends a request for the new page. The server then compiles the new page, and finally sends it to the browser.This process involves three data journeys across the internet instead of one. Latency in the internet is probably the cause of the delays which you are finding.

Why do you want to change http://www.example.com to http://www.example.com/index.php? They represent the same address, after all.

Re: strange 'REQUEST_URI page load delay

Posted: Mon Apr 04, 2011 5:06 pm
by stevestark5000
i am having a problem with logout. when the user logout then the user sees the login page but if the user go to index.php instead of logging in then the user will be logged in again. the index.php redirect fixes that issue.

[SOLVED} i just took the code out and to my surprise everything worked