|
-
October 9th, 2005, 01:26 PM
#1
Executing code at a specific time
Hey guys, I am working on a project now where I wanted to implement automatic database maintenance. I basically need to clean old records from the system every morning at 12:01AM. Is there a way to do this reliablely with PHP or am I going to have to implement a server-based solution? Thanks for the input guys, you're always the best!
Jason Palmer
Webmaster Digital-Play Web Designs
http://webdesign.digital-play.com/
-
October 9th, 2005, 08:45 PM
#2
Re: Executing code at a specific time
Can't be done with PHP unless you plan to set a refresh statement. Best option is to set the script to run from a task scheduling agent. Worst case scenario is using JavaScript to detect the time with a setTimeout() and tell it too look for the time and then refresh the browser accordingly.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
October 9th, 2005, 09:07 PM
#3
Re: Executing code at a specific time
CRON. just write a script that does the work, and schedule it w/ a cron job, & it will get done at the specified time. I've done this w/ databas back up (where it would back up the db, tarball the directory & email it to me).
-
October 9th, 2005, 10:29 PM
#4
Re: Executing code at a specific time
I knew I could count on you guys for a fast response! Thank you all for your input! Earlier today I was actually looking into using CRON however I was given the impression that the execution of the job depends solely on if people visit the site regularly. So, if I am correct in my interpretation, then if there was a day when no one visited my site from 11pm until 8am the next morning, that the scheduled job that was supposed to execute at 12:01AM would not execute until 8AM the next morning when someone finally told the server to refresh by visiting the page. Is this true? At first, this will NOT be a high traffic site.
-
October 9th, 2005, 10:58 PM
#5
Re: Executing code at a specific time
So then run a JavaScript code that refreshes a page with PHP every time the clock hits 00:01.
Code:
<html>
<body onload="update()">
<script language="JavaScript">
function update(){
var digital = new Date();
var h = digital.getHours();
var m = digital.getMinutes();
var s = digital.getSeconds();
time = h + ":" + m + ":" + s;
if(time=="00:01:00"){window.location.reload();}
setTimeout("update()", 1000);
}
</script>
<?php
//PLACE PHP CODE TO CLEAN DATABASE HERE.
?>
</body>
</html>
***But use this as last case scenario.
Last edited by peejavery; October 9th, 2005 at 11:33 PM.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
October 9th, 2005, 11:20 PM
#6
Re: Executing code at a specific time
 Originally Posted by kanji2150
I knew I could count on you guys for a fast response! Thank you all for your input! Earlier today I was actually looking into using CRON however I was given the impression that the execution of the job depends solely on if people visit the site regularly. So, if I am correct in my interpretation, then if there was a day when no one visited my site from 11pm until 8am the next morning, that the scheduled job that was supposed to execute at 12:01AM would not execute until 8AM the next morning when someone finally told the server to refresh by visiting the page. Is this true? At first, this will NOT be a high traffic site.
well no.
as MadHatter pointed out, you can use some CRON job to do this. and the cron job doesn't rely on the webserver. just execute the script with the command-line php interpreter - via the cron job.
the solution posted by peejavery is a little bit unsuitable for your purpose... his solution in deed depends on some people keeping open the webpage...
there are 10 kinds of people. those who understand binary and those who don't...
rate a post if you find it usefull, thx
check out my Firefox/Mozilla Extension: http://urlparams.blogwart.com/
-
October 10th, 2005, 01:40 AM
#7
Re: Executing code at a specific time
Thanks again for all the replies guys! Ideally, I am looking for a client-side solution because I do not have direct access to the web server that our pages are hosted on. I will have to request that a CRON job be added, and that request may not be satisfied. Are there any other solutions that you guys can think of? We are also going to be developing a visual basic application that will act as the adminstrator to this software. It has a connection to our MySQL database, however the computers it will be installed on have to be turned off by 5pm every day lol. I don't know what to do.. I'm about to just dedicate one of my machines to call a script at 12:01 everyday haha!
-
October 10th, 2005, 03:02 AM
#8
Re: Executing code at a specific time
if it were me, I'd still write the script that does what you need, and set up a cron job on *my* machine that logged in and ran the script (which would archive the site and email it back to me, or whatever you're doing).
if you can connect to your database from outside the webserver, then I say just write a little app that logs into it and pulls the info out that way.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|