Search code examples
phpoptimizationuname

How fast is php_uname()?


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?


Solution

  • 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.