homepage Welcome to WebmasterWorld Guest from 54.197.110.151
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
how to make this script execute once a day
by writing a log file
lindajames

10+ Year Member



 
Msg#: 1570 posted 3:19 pm on Aug 21, 2003 (gmt 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

 

bcolflesh

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1570 posted 3:27 pm on Aug 21, 2003 (gmt 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

lindajames

10+ Year Member



 
Msg#: 1570 posted 3:45 pm on Aug 21, 2003 (gmt 0)

i dont have access to cron jobs plus im on windows IIS server

mavherick

10+ Year Member



 
Msg#: 1570 posted 3:56 pm on Aug 21, 2003 (gmt 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

bcolflesh

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1570 posted 3:57 pm on Aug 21, 2003 (gmt 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.

lindajames

10+ Year Member



 
Msg#: 1570 posted 4:46 pm on Aug 21, 2003 (gmt 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

mavherick

10+ Year Member



 
Msg#: 1570 posted 5:01 pm on Aug 21, 2003 (gmt 0)

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

mavherick

dreamcatcher

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



 
Msg#: 1570 posted 7:37 pm on Aug 21, 2003 (gmt 0)

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

:)

lindajames

10+ Year Member



 
Msg#: 1570 posted 7:47 pm on Aug 21, 2003 (gmt 0)

How do you create a Fake Cron using a CGI script that simulates a cron feature?

bcolflesh

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1570 posted 7:54 pm on Aug 21, 2003 (gmt 0)

I think he's refering to:

smarterscripts.com/cron/

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

bcolflesh

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1570 posted 7:55 pm on Aug 21, 2003 (gmt 0)

Hmmm - maybe this will help you:

kalab.com/freeware/cron/cron.htm

dreamcatcher

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



 
Msg#: 1570 posted 12:18 am on Aug 23, 2003 (gmt 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!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved