FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


EDIT: document root





snowboardalliance
EDIT:
Is it any slower to use
Code:
$rootpath = $_SERVER['DOCUMENT_ROOT'] . '/';

instead of
Code:
$rootpath = '/home/user/public_html/folder/folder2/';

?
asiddle423
you could have the code where the link is equal either to a variable or an array and then use the include syntax with the variable and then echo the varaiable or array in your code some where.

Variable Example:

<?php
$linkName = "include1.inc";
$linkName2 = "include2.inc";

include($linkName);

echo('The script name is '.$linkName);
?>

Array Example:
<?php
$linkName[0] = "include1.inc";
$linkName[1] = "include2.inc";

include($linkName[0]);

echo ('The script name is '.$linkName);
?>
asiddle423
I would say that it is slower to use

Code:
$rootpath = $_SERVER['DOCUMENT_ROOT'] . '/';


but you wont see any difference so i would stick with that code as it is more accurate and you wouldn't need to update the script if you changed the file name.
cafefort
There's NO difference in speed AT ALL Smile

The variable $_SERVER['DOCUMENT_ROOT'] is ready to use
you can use it or not, but it's there in the memory.
This writing don't query the server or such, so there's nothing
to load or to think of for the server...

In the other hand:

Code:
$rootpath = $_SERVER['DOCUMENT_ROOT'] . '/';


this syntaxe is more flexible and server-independant and almost application
independant ; i mean you can move your application wherever you want
this will work. You can even change the location of your webapp in the server
the $rootpath will be the same.

Hope this helps Smile
Antoine_935
cafefort wrote:
There's NO difference in speed AT ALL Smile

The variable $_SERVER['DOCUMENT_ROOT'] is ready to use


I think it's not ready to use, for performance reasons. When you use a $_SERVER variable, PHP maybe calls a getenv() function. I coded an interpreted language, I know what I'm speaking about. The most likely is that PHP does not initialize this var at every startup.

Now... the speed loss is so small that, for portability reasons you should use this Wink So that when you change server you don't have to change this.
cafefort
Quote:
cafefort wrote:
Quote:
There's NO difference in speed AT ALL Smile

The variable $_SERVER['DOCUMENT_ROOT'] is ready to use


I think it's not ready to use, for performance reasons. When you use a $_SERVER variable, PHP maybe calls a getenv() function. I coded an interpreted language, I know what I'm speaking about. The most likely is that PHP does not initialize this var at every startup.


Yes, you may be right... the call to getenv() function...
but, what a waste of time if this call is made at every use of a
$_SERVER['something'] variable!

Anyway, I think PHP coders (the ones that coded php and its libraries) did thought about this and I trust they optimized this kind of stuff with "caching" methods.

And yes, the difference in all cases is very very very small that we
should use that syntaxe Smile

thanks.
AftershockVibe
Well, since you have to fetch an extra pointer at the least it will be marginally slower. This is going to be in terms of microseconds though! I really wouldn't worry too much!
Related topics
[tutor] How to protect images without htaccess using PHP
.htaccess problem
How to load external text and html?
Configuring Linux / Windows Dual Boot
Intranet
Path Info Again
[PHP] Faking Shell Access Through PHP
FreeBSD. My installation exprerience.
Transfering to a .com
php instalation:
uid and guid need to be set?
Dúvidas CPanel
Domains - ~FreeDNS help please!~ :)
Directory Based vHosts?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.