I need get the server time

Trevelin

New Member
Messages
12
Reaction score
0
Points
0
I'm new in the PHP, for that i have question that for the most of you are basic. I need get the server time to shoot actions of the site i'm desing.
This is what i need: when the server time gets 00 hs, 00 min, 01 sec, my main page will change. Someone can explain how do that?

Thanks.:biggrin:
 

konekt

New Member
Messages
100
Reaction score
0
Points
0
There are many ways of doing something like which you have described, but it will all depend on the specifics.

Are you loading a new page every 24hrs? If so you may want to consider Cron Jobs.

Do you need a page loaded between certain times? If so, what are those times? If, say, it were between 00->6 you can do do something like:

Code:
if(date('H') > 0 || date('H') < 6)
{
//code for page
}

You could also do that for one time loads, like a site opening, just play around with the date() function.
 

MasterMax1313

New Member
Messages
84
Reaction score
0
Points
0
if you need a client's page to refresh or load a different page at a specific time you could make some javascript to check the hour until you're close to the hour then increase the frequency of the timer so that it catches the second that you need it, at which point you could use AJAX to ask the server for the time, but keep in mind that will really increase the number of page requests the server is handling and therefore it will increase bandwidth used.

the other option of using a cron job is also viable if you are simply looking to change the page at a specific time, at which point i'd suggest making an AJAX script to check maybe once an hour or so to see if the page is updated, through a variable being set or something like that, then refresh the page if that is the case.
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
I don't think ajax is necessary if he's looking to have the page refresh at a certain time. If the server just gives JS its current time on page load(e.g., onload="init(<?php print time(); ?>")), and then JS keeps track of how much time has passed since page load, then the client shouldn't need to make any requests to determine the server's approximate time.
 

MasterMax1313

New Member
Messages
84
Reaction score
0
Points
0
granted, but it is possible that they will fall out of sync, though it shouldn't be by much. one thing to keep in mind when dealing with timers is that even though timer functions say that the time is in milliseconds, it is only an approximation that the computer uses and the computer calls the function at its turn (or something like that). I've had timers that are supposed to run for 15 minutes be done in closer to 14 minutes, so my personal fix is to check the current time against the previous time stored (based on seconds typically), and if the seconds are different, then update the variable holding the time.
 

Trevelin

New Member
Messages
12
Reaction score
0
Points
0
Thanks everyone, i will use Cron Jobs, like i say i'm a newbie in this, and just yesterday i read what a Cron Job is. Now i see a lot of more things to do, to make with my proyects.

Again, thanks.

(I will came with more question ;) :p )
 
Top