View Full Version : php time driven events??? need some help!!!
aleman84
06-21-2006, 08:39 PM
Basically I need to do an event every minute (60 seconds) and display the minutes on the page. So I need a looped function that displays the minute it is on and do a function every time as well.
I understand I need to do a loop based on time (60 seconds) but dont know how!!! It also needs to stop once its done it for 45 minutes.
can any one help?
Need help big time, thank you.
not with php, javascript is the right language.
<script type="text/javascript">function clock() {
d = new Date();
h = d.getHours();
min = d.getMinutes();
document.getElementById('blah').innerHTML = h + ":" + min;
setTimeout("clock()", 60000);
}
window.onload = clock;
</script>
<span id="blah"></span>
djr33
06-22-2006, 06:34 AM
Indeed. PHP operates server side and will only be executed when a page loads... there is no way for it to react to time, user input (like mouseover, clicking, pressing a key, etc.).
(There is AJAX which uses javascript to go behind the scenes and grab a php page, but that is still based in javascript, and is very complex to learn, and you don't need it here.)
aleman84
06-24-2006, 11:58 AM
thank you, after a bit of research I got that answer too! its a hard old language php at times, I do asp.net too and thats all in one!! php needs to be expanded! a php.net lol! Well javascript here I come! ready or not! lol thanks for the help.
aleman84
06-24-2006, 12:05 PM
another question, if i place this on a php page, the page loads. It should display 0:01 then 0:02 ....... and so on till it hits 0:59 then shows 1:00, 1:01.
On the 1:00 I want a function to perform and do this every minute for 45 minutes.
I hope this is clear, if the page has to reload it has to reload but I would like just the function to perform over and over again.
Cheers.
BLiZZaRD
06-25-2006, 07:17 AM
If you were using Flash I could make it work in a few seconds.. LOL
Although it seems you are basically asking the same thing... you have one that executes every second...
So can't you write another one using the same standards, that checks the first and when that is at 60 seconds execute the second?
I am no JS guy... Hell, I am not much good at anything except Flash, and even that is ify.. LOL But it seems logical to me...
djr33
06-25-2006, 07:55 AM
You seem to have missed the point. PHP needs to reload, and reloading takes more than a second in many cases... it won't work. I tried a 1sec refresh rate on something one time and it displayed nothing because it was reloading before it got the info... weird.
You'd want to use javascript here.
It's pretty simple, but I don't know the exact code...
1. Count time.
2. Every 1000 microseconds, add 1 to the time.
3. If (time==100) {time = 0; min++;}
4. If (min==45)...end...or?
Look up code for counting time; look up code for displaying on a page.
That's it.
mady369
07-25-2006, 04:58 PM
values of certain fields of a table in a database has to change at the start of every year(1st jan), is this possible in a MYSQL database or please tell me how to work around it, i am using JSP and javascripting... thanks in advance.
Cron jobs are the best idea here.
blm126
07-25-2006, 10:41 PM
This is a really bad idea,but you can do it like this in PHP.
<?php
set_time_limit('3000');
function callthis(){
//function called once every minute
}
$i = 1;
while($i <= 45){
sleep('60');//change this to 1 for testing,that's what I did
callthis();
echo $i." minutes\n";
flush();
$i++;
}
?>
In fact it's such a totally bad idea that you shouldn't even bother. Especially since the default timeout for PHP scripts is 30 seconds. :p
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.