Welcome to WebmasterWorld Guest from 50.19.0.90

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

how to make this script execute once a day

by writing a log file

     
3:19 pm on Aug 21, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Mar 10, 2003
posts:321
votes: 0


hello, i've got the following code deletes the entire content of a folder called "temp"

<?php
$dh = opendir(temp) or die ("Could not open temp directory");
while (false!== ($file = readdir($dh)))
{
if ($file!= "." && $file!= "..")
{
unlink("temp/$file") ;
echo "<font face=Verdana size=1>All Files Deleted...</font>";
}
}
?>

but i wanted to do some simple validation on it so that it only executes the deletion once a day.

basically, the script is going to execute everytime but i dont want the contents of the entire folder to be deleted everytime the script is executed. i want the script to run 2 validation rules

firstly to check if the server time is between 11:30PM and 11:49PM if it is not then the script doesnt do anything, but if it is the script basically checks a log file to see if the script has already been executed by someone else, if it has then it doesnt do nothing. but if it hasnt, it deletes the entire contents of the "temp" folder and then writes a log so that when someone else tries to execute the script it wont delete.

I've created a peace of perl code that executes a script only once a day by logging data in a file. the code looks like this:

open(TIME, "runonce.log");
$lastrun = <TIME>;
close(TIME);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
if($lastrun == $yday) {
print "Content-type: text/html\n\n";
exit;
} else {
open(TIME, ">runonce.log");
print TIME $yday;
close(TIME);
}

Maybe that can help someone to help me get this done in PHP. any help would be very much appreciated.

cheers
linda

3:27 pm on Aug 21, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 21, 2003
posts:2355
votes: 0


Setup a cron job that runs your script - or have your admin set it up for you.

Check:

phpfreaks.com/tutorials/28/0.php

3:45 pm on Aug 21, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Mar 10, 2003
posts:321
votes: 0


i dont have access to cron jobs plus im on windows IIS server
3:56 pm on Aug 21, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:June 3, 2002
posts:169
votes: 0


There's an option in the control panel called "Scheduled Task", I've never used it but it might be something to look into.

mavherick

3:57 pm on Aug 21, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 21, 2003
posts:2355
votes: 0


The Windows server admin could schedule your script to run, or you can setup Task Scheduler to run it from your machine - as long as it's turned on and connected to the Internet.
4:46 pm on Aug 21, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Mar 10, 2003
posts:321
votes: 0


i dont have access to that either im using a shared hosting account not managed. thats why the only option i have is to do it script based
5:01 pm on Aug 21, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:June 3, 2002
posts:169
votes: 0


Like bcolflesh mentionned, use the task scheduler on your own machine to call up the script on your site.

mavherick

7:37 pm on Aug 21, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 30, 2003
posts:3719
votes: 0


You can try using Fake Cron, a CGI script that simulates a cron feature.

:)

7:47 pm on Aug 21, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Mar 10, 2003
posts:321
votes: 0


How do you create a Fake Cron using a CGI script that simulates a cron feature?
7:54 pm on Aug 21, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 21, 2003
posts:2355
votes: 0


I think he's refering to:

smarterscripts.com/cron/

Requires a Perl module that I doubt most Windows hosts have installed though.

7:55 pm on Aug 21, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 21, 2003
posts:2355
votes: 0


Hmmm - maybe this will help you:

kalab.com/freeware/cron/cron.htm

12:18 am on Aug 23, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 30, 2003
posts:3719
votes: 0


I think he's refering to:
smarterscripts.com/cron/

Requires a Perl module that I doubt most Windows hosts have installed though.

Yes, thats the one. I wasn`t sure if I could post a link or not. Sorry it wasn`t helpful!

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members