Hi,

Please consider the below code.

<html>
<body>

<?php

$time1 = localtime();
echo $time1[0];


echo("<br /><br />");


/* HERE SOME CODES RELATED TO CERTAIN FUNCTIONS LIKE DISPLAYING OF SOME IMAGE ETC. IS EXECUTED. APPROXIMATELY IT TAKES 10 SECONDS FOR THE COMPLETE EXECUTION OF THESE FUNCTIONS. SINCE IT IS IRRELEVANT TO MY QUESTION, I REMOVED THEM FOR THE SAKE OF KEEPING THIS PIECE OF CODE SIMPLE.   */


echo("<br /><br />");


$time1 = localtime();
echo $time1[0];


?>

</body>
</html>

OK, now I get the following output when I execute the above code:

48

**** THE OUTPUT OF THE FUNCTIONS LIKE LOADING CERTAIN IMAGES.  NOTE: IT TAKES APPROX. 10 SECONDS FOR THIS OUTPUT TO COMPLETELY APPEAR ON THE SCREEN

48

Now, my question is:
In the beginning and ending of the code, I echoed localtime()[0] which displays the 'seconds' value of the current time. But in the middle of the code, I executed certain functions which took approx. 10 seconds to get executed. Then how come localtime()[0] present in the ending outputted the same value which it outputted in the beginning??

I suspect that it isn't taking anything like 10 seconds to execute the functions that you didn't show. That's a long time on a fast machine. Put a sleep command in just after all the code that you didn't show and I'll bet that you'll see a difference in the two values. The time until it displays might be quite long because of network transmission time or the time it takes the browser to deal with it but it may not be anywhere near that amount of time on the server. If you want to see how much time it is actually taking use / display the microtime before and after.

I suspect that it isn't taking anything like 10 seconds to execute the functions that you didn't show. That's a long time on a fast machine. Put a sleep command in just after all the code that you didn't show and I'll bet that you'll see a difference in the two values. The time until it displays might be quite long because of network transmission time or the time it takes the browser to deal with it but it may not be anywhere near that amount of time on the server. If you want to see how much time it is actually taking use / display the microtime before and after.

Ok, it seems you are right! I added that sleep command and got the correct time difference this time.

Thanks a lot for your time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.