View Full Version : Recursive timed execution?
gorilla1
02-03-2003, 01:14 PM
I want to execute a php function, wait a few minutes, execute it again, etc. Can I do this using javascript? I'm not real sure how I would call the php program, or whether I could have the script be idle while waiting.
G
There is a way, but it all depends on what your php script is supposed to do.
make your page show inside a frameset that has a frame with 1pixel size. Ex.:
<frameset cols="*,1">
<frame src=MainPage name=main>
<frame src=phpFunctionPage name=phpWindow scrolling=no>
</frameset>
Then, on your main page, and every other page on your site you want the php function to work when they are loaded, add a function like this to the body's onload event:
function phpRefreshFunction(){
var seconds2refresh = 5;
window.open(phpFunctionPage,phpWindow,'');
setTimeout("phpRefreshFunction()", seconds2refresh*1000);
}
--------------------------------------------------
this function opens the phpFunctionPage in the phpWindow frame every 5 seconds. Now, I don't know what your php script does, if it needs you to pass any variables or if it is supposed to change anything on the page, but this was just an idea.
gorilla1
02-03-2003, 06:40 PM
Nice idea, thanks. The php script is going to do some work on the server - background, administrative work - this whole thing wont even run on a client web page - just on an admin backend page. I jsut want to be able to stagger the server work. It could be done with meta refresh I suppose, except that that wont allow a recursive approach. So basically, launch the php script, wait around, launch it again, etc.
G
glenngv
02-05-2003, 02:23 AM
easier way:
function phpRefreshFunction(){
var php = new Image();
php.src = "page.php";
}
setInterval("phpRefreshFunction()",60000);//1 minute interval
whammy
02-05-2003, 04:21 AM
The old "tricky pixel" rears its head again. I use this in ASP sometimes (but for different purposes). ;)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.