localtime() not working as expected.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
el33t
Forum Newbie
Posts: 3
Joined: Wed Oct 06, 2010 12:56 am

localtime() not working as expected.

Post by el33t »

Hi,

Please consider the below code.

Code: Select all

<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??

Regards,
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: localtime() not working as expected.

Post by requinix »

1. Except for the stuff represented by the comment, is that exactly the code you're using?
2. If you add a sleep(15); before the second call to localtime(), what happens?
el33t
Forum Newbie
Posts: 3
Joined: Wed Oct 06, 2010 12:56 am

Re: localtime() not working as expected.

Post by el33t »

tasairis wrote:1. Except for the stuff represented by the comment, is that exactly the code you're using?
2. If you add a sleep(15); before the second call to localtime(), what happens?

1. Yes. The code is exactly the same.

2. Hey, I did what you asked and I got a different output!
Here is the output screen.
14

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

29
So, whats up with this? Any help would be greatly appreciated.
Post Reply