[PHP] Does requesting $_SERVER variables need to query the server

2011-02-23 Thread Marc Guay
This question will probably reveal my lacking knowledge of the
fundamentals, but I'm a go for it anyway:

When you use a $_SERVER variable, is a query made to the server to get
the information or is it just sitting in a variable all ready to go?
Reworded, is there any efficiency gained by storing the data in a
local variable if it's going to be used many times in the script?
My experience with jQuery has taught me to store $(objects) in local
variables if they're going to be used repeatedly because the DOM is
queried every time a jQuery object is generated, so I'm wondering if a
similar logic applies.

Example:

if ($_SERVER['SCRIPT_NAME'] == 'how.php')
// do stuff
if ($_SERVER['SCRIPT_NAME'] == 'why.php')
// do other stuff

vs.

$script_name = $_SERVER['SCRIPT_NAME'];

if ($script_name == 'how.php')
// do stuff
if ($script_name  == 'why.php')
// do other stuff

Cheerios,
Marc

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Does requesting $_SERVER variables need to query the server

2011-02-23 Thread Shreyas Agasthya
Marc,

$_SERVER is an array and it should have all the information. I do not know
the answer for the latter part of your query.

Regards,
Shreyas

On Thu, Feb 24, 2011 at 12:30 AM, Marc Guay marc.g...@gmail.com wrote:

 This question will probably reveal my lacking knowledge of the
 fundamentals, but I'm a go for it anyway:

 When you use a $_SERVER variable, is a query made to the server to get
 the information or is it just sitting in a variable all ready to go?
 Reworded, is there any efficiency gained by storing the data in a
 local variable if it's going to be used many times in the script?
 My experience with jQuery has taught me to store $(objects) in local
 variables if they're going to be used repeatedly because the DOM is
 queried every time a jQuery object is generated, so I'm wondering if a
 similar logic applies.

 Example:

 if ($_SERVER['SCRIPT_NAME'] == 'how.php')
 // do stuff
 if ($_SERVER['SCRIPT_NAME'] == 'why.php')
 // do other stuff

 vs.

 $script_name = $_SERVER['SCRIPT_NAME'];

 if ($script_name == 'how.php')
 // do stuff
 if ($script_name  == 'why.php')
 // do other stuff

 Cheerios,
 Marc

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Regards,
Shreyas Agasthya


Re: [PHP] Does requesting $_SERVER variables need to query the server

2011-02-23 Thread Daniel P. Brown
On Wed, Feb 23, 2011 at 14:00, Marc Guay marc.g...@gmail.com wrote:
 This question will probably reveal my lacking knowledge of the
 fundamentals, but I'm a go for it anyway:

 When you use a $_SERVER variable, is a query made to the server to get
 the information or is it just sitting in a variable all ready to go?
 Reworded, is there any efficiency gained by storing the data in a
 local variable if it's going to be used many times in the script?
 My experience with jQuery has taught me to store $(objects) in local
 variables if they're going to be used repeatedly because the DOM is
 queried every time a jQuery object is generated, so I'm wondering if a
 similar logic applies.

$_SERVER is just a prepopulated superglobal array that is created
at runtime.  When the script is executed via the web, PHP and the web
server (for example, Apache) generate numerous environment values as
directed by their configuration.

The quickest way to learn about this in more detail is to use it's
nickname in Google: EGPCS.  The actual configuration directive is
variables_order, but many folks - particularly the PHP3/4 and very
early PHP5 - will be more familiar with the nickname, which is an
acronym for the default order of superglobals: Environment, Get, Post,
Cookie, Server.

-- 
/Daniel P. Brown
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Does requesting $_SERVER variables need to query the server

2011-02-23 Thread Marc Guay
    $_SERVER is just a prepopulated superglobal array that is created at 
 runtime.

Thanks for the clear answer.

Marc

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Does requesting $_SERVER variables need to query the server

2011-02-23 Thread Marc Guay
  so when
 you're using $_SERVER variables there's no call back to the server, as the
 code is still being run on the server at that point.

This is something I actually do understand.  I was wondering if the
code running on the server had to query the server for the information
every time a $_SERVER var was referenced, but like Daniel explained,
the contents of the $_SERVER array are populated at runtime and so no
further hey server, what version of apache are you running?
questions need to be asked of it.

Marc

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php