The result shows that __FILE__ is the fastest, so use that when you don't have to use any other method to find the script's self. __FILE__ is a built in constant show the location of the running script. Note that each one of those ways can return different things(like PHP_SELF is different than REQUEST_URI when used some mod_rewrite) but most times those have the same usage, refer to self.
Here is the code for the result:
$timeparts = explode(' ',microtime());
$starttime = $timeparts[1].substr($timeparts[0],1);
$i = 1000;
while($i){
__FILE__;
--$i;
}
$timeparts = explode(' ',microtime());
$endtime = $timeparts[1].substr($timeparts[0],1);
echo '<br />__FILE__;',bcsub($endtime,$starttime,6);
$timeparts = explode(' ',microtime());
$starttime = $timeparts[1].substr($timeparts[0],1);
$i = 1000;
while($i){
$_SERVER['PHP_SELF'];
--$i;
}
$timeparts = explode(' ',microtime());
$endtime = $timeparts[1].substr($timeparts[0],1);
echo '<br />','$_SERVER["PHP_SELF"];',bcsub($endtime,$starttime,6);
$timeparts = explode(' ',microtime());
$starttime = $timeparts[1].substr($timeparts[0],1);
$i = 1000;
while($i){
$_SERVER['SCRIPT_NAME'];
--$i;
}
$timeparts = explode(' ',microtime());
$endtime = $timeparts[1].substr($timeparts[0],1);
echo '<br />','$_SERVER["SCRIPT_NAME"];',bcsub($endtime,$starttime,6);
$timeparts = explode(' ',microtime());
$starttime = $timeparts[1].substr($timeparts[0],1);
$i = 1000;
while($i){
$_SERVER['REQUEST_URI'];
--$i;
}
$timeparts = explode(' ',microtime());
$endtime = $timeparts[1].substr($timeparts[0],1);
echo '<br />','$_SERVER["REQUEST_URI"];',bcsub($endtime,$starttime,6);
$timeparts = explode(' ',microtime());
$starttime = $timeparts[1].substr($timeparts[0],1);
$i = 1000;
while($i){
getenv('REQUEST_URI');
--$i;
}
$timeparts = explode(' ',microtime());
$endtime = $timeparts[1].substr($timeparts[0],1);
echo '<br />','getenv("REQUEST_URI");',bcsub($endtime,$starttime,6);
$timeparts = explode(' ',microtime());
$starttime = $timeparts[1].substr($timeparts[0],1);
$i = 1000;
while($i){
getenv('SCRIPT_NAME');
--$i;
}
$timeparts = explode(' ',microtime());
$endtime = $timeparts[1].substr($timeparts[0],1);
echo '<br />','getenv("SCRIPT_NAME");',bcsub($endtime,$starttime,6);
$timeparts = explode(' ',microtime());
$starttime = $timeparts[1].substr($timeparts[0],1);
$i = 1000;
while($i){
getenv('SCRIPT_URL');
--$i;
}
$timeparts = explode(' ',microtime());
$endtime = $timeparts[1].substr($timeparts[0],1);
echo '<br />','getenv("SCRIPT_URL");',bcsub($endtime,$starttime,6);
Recent comments
4 hours 25 min ago
22 hours 6 min ago
1 day 7 hours ago
2 days 16 hours ago
3 days 20 hours ago
4 days 32 min ago
4 days 33 min ago
4 days 39 min ago
4 days 16 hours ago
4 days 17 hours ago