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);
Bookmark/Search this post with:
[...] WebDevLogs ? Which way
[...] WebDevLogs ? Which way to get the PHP self script name is the fastest? (tags: Tech WebDev PHP Performance Tips) [...]
funny :P
funny :P
__FILE__ given included script name
__FILE__ given included script name if use in include file or class as a function...
pls check again,,and give me answer as soon as possible.
Post new comment