3

How fast is php_uname() say doing php_uname('s n') or php_uname('a'). The reason I ask is because I'd like to use it to determine which server I'm on and therefore the configuration (paths, etc).

This is related to Is there a PHP function or variable giving the local host name?

Community
  • 1
  • 1
Darryl Hein
  • 142,451
  • 95
  • 218
  • 261

2 Answers2

3

I just did this:

<?php
  $tstart = microtime(true);

  php_uname('a');

  print 'it took '. sprintf("%f",microtime(true) - $tstart) ." seconds\n";
?>

And it produced this:

it took 0.000016 seconds

That is on a Core2Duo 2.4GHz Debian box.

I know it is an empirical test and all but I think that it shows that it will be fast enough for you.

I did not expect it to take a long time since uname only needs to make a very simple call to the kernel.

Adam Pierce
  • 33,531
  • 22
  • 69
  • 89
0
$_SERVER['HTTP_HOST']
Steve
  • 5,823
  • 7
  • 31
  • 33
  • Just if anyone stops by here for the same question... this does not work if you're running PHP independently of a web server, e.g. in a cronjob. – Wolfgang Stengel Dec 09 '13 at 10:21