Page 1 of 1

PHP Execution time and geographic location!

Posted: Mon Jun 15, 2009 12:19 pm
by tobia
Hi all,

I have a very simple php script that echos 500k of simple text. I'm measuring the execution time of this script using microtime() but I'm getting strange results.

When I load the page from a local client (local to the server - USA, CA) I get something around 0.03s. From a client in Europe I get 3.5 secs! At first I was thinking....ok...it's some problem on the network....but I don't see how....any problem in the network connection can change the execution time of the page!
am I missing anything?

any idea?
Thanks

Re: PHP Execution time and geographic location!

Posted: Mon Jun 15, 2009 12:30 pm
by Benjamin
:arrow: Moved to PHP - Code

Can you post the code please?

Re: PHP Execution time and geographic location!

Posted: Mon Jun 15, 2009 12:43 pm
by tobia
Sure,

The body is just a repetition N-times of the content in the <p>
You can check the debug class in the second session of code!

As you can see is really really simple....I don't see how can change the execution time based on a geographic location!

thanks a lot


Code: Select all

<?
    define("AURORA_HOME","/var/www/html/aurora/");
    require_once(AURORA_HOME."includes/utils/Debug.php"); 
    
    $debug = new Debug();
    $debug->StartTimer();
 
?><html>
<body>
<p>
Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br>
Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br>
Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br>
Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br>
</p>
.
.
.
.
.
</body>
</html><?    
    
    echo $debug->getTimerValueInSec();
?>

Code: Select all

<?
 
 
    class Debug {
    
        private $startTime;  
        
        function Debug() {
        
        }
        
        function StartTimer() {
            $mtime = microtime(); 
            $mtime = explode(' ', $mtime);  
            $this->startTime = $mtime[1] + $mtime[0];        
        }
        
               
        function getTimerValueInSec() {
            $mtime = microtime(); 
            $mtime = explode(" ", $mtime);  
            $endtime = $mtime[1] + $mtime[0];     
            return ($endtime - $this->startTime); 
        }
            
    }
  
?>

Re: PHP Execution time and geographic location!

Posted: Mon Jun 15, 2009 1:03 pm
by requinix
One word: bandwidth. But not in the "lol i get 1gbps dnload wut do u get" sense.

The Internet is a series of tubes...

PHP can't flush 500k of text through those tubes all at once: they just aren't large enough. It can put in, say, 1000 gallons of text before the tube gets filled up. Then PHP has to wait for somebody at the other end to let some stuff drain out before it can send more.

Now it goes without saying: your local connection is much faster than your connection to Europe. It only takes 0.03 seconds for PHP and your browser to do this elaborate open-tube/put-stuff-in-tube/close-tube thing because they're right next to each other. But from Europe it takes time: the browser doesn't know the tube has stuff in it because the guy putting stuff inside has to yell all the way from Europe that the browser should open the tube.

(And yes, the analogy isn't quite correct, but it gets the point across.)

Re: PHP Execution time and geographic location!

Posted: Mon Jun 15, 2009 1:06 pm
by tobia
Good to hear that! Thank you very much!