It's all hypothetical, I am not doing this yet. Let's say I have to get a page URL 5 times using: h t t p://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; 1. Is it the only way I can do this? 2. Will it drain the resources? I mean, is it like sending a request to get the same page 6 times (counting the original request) or no?
If you're doing it five times, why not just assign it to a static variable? $page = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; PHP: And, to be absolutely sure it works regardless, do this: $page = ((isset($_SERVER['HTTPS']) ? 'https' : 'http').'://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; PHP: Then you only call it once, and can reuse the variable as needed.
That is the best way imo. No, the values are generated by Apache and send to PHP regardless of you using them or not. There is no cost associated with using them that won't come from using another variable.