Click to See Complete Forum and Search --> : scheduling events


diamonds
10-10-2003, 08:08 AM
How do you schedule events with PHP, say, to update a static page or image(GD) every day at midnight.

Searching localy and web-wide (http://www.google.com) didn't help.

pyro
10-10-2003, 08:23 AM
You need to run a cron (http://www.sitepoint.com/article/1196). If you have CPanel on your server, it includes an easy to understand crontab to use.

diamonds
10-10-2003, 08:34 AM
Iv'e heard about Cron, but how do you make it function in windows?

pyro
10-10-2003, 08:42 AM
You don't. In Windows, I believe you need to schedule an event. Dern Windows servers... :p

diamonds
10-10-2003, 08:49 AM
Which is?

pyro
10-10-2003, 08:52 AM
You'd have to try searching google for that one... I'm not even sure if I'm right as to how you'd do it on a windows box... I'm lucky enough to be on a linux server... :)

diamonds
10-10-2003, 09:34 AM
I found a version for windows :
http://www.kalab.com/freeware/cron/cron.htm

It works...
Every minute it updates the log file with somthing like "10.10.2003 10:22 .../update.php"
if the only line in the config file is

* * * * * .../update.php

however, it does not appear to be executing the PHP code, I tested it with a test file from PHP.net that writes text to a file.
When I go the URL, it writes to the file. When executed by cron, it does nothing.

Am I doing somthing wrong?
yes: .../ is replaced by the actual file path(like "c:/apache/htdocs/").

pyro
10-10-2003, 09:40 AM
Try:

* * * * * php C:\path\to\your\file.php

diamonds
10-10-2003, 11:33 AM
That reports "file not found"

however:

10.10.2003 12:17 php: c:/.../update.php
AND
10.10.2003 12:17 php: /.../update.php
AND
10.10.2003 12:17 php:c:/.../update.php
AND
10.10.2003 12:17 php:/.../update.php

all report:


10.10.2003 12:17 Error: The operating system denied access to the specified file.

Do I need to actavate somthing?

fyrestrtr
10-10-2003, 12:08 PM
Start --> All Programs --> Accessories --> System Tools --> Scheduled Tasks

(for Windows XP)

You need to tell it to execute the file, or browse to it (which you can do with a simple batch file). Once you get the batch file sorted, stick it in a task and set the schedule.

diamonds
10-10-2003, 12:31 PM
I want to know exactly how torun an entire php file:
for example, if a PHP file conatins:

<?php
$filename = 'test.txt';
$somecontent = "Add this to the file\n";

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
print "Cannot open file ($filename)";
exit;
}

// Write $somecontent to our opened file.
if (!fwrite($handle, $somecontent)) {
print "Cannot write to file ($filename)";
exit;
}


fclose($handle);

} else {
print "The file $filename is not writable";
}
?>
I want it to find the file to write to, than write to it.
How do you do that?
say, every day at midnight?

assume I know nothing.

diamonds
10-10-2003, 12:40 PM
How do you execute a php page from the command line in windows?

diamonds
10-10-2003, 01:53 PM
Never mind, I got it working!
Thanks, pyro, for your help.

Here is a summary of what to do:
download cron for windows at:
http://www.kalab.com/freeware/cron/cron.htm

edit the crontab file:

* * * * * c:/php/php.exe c:/path/to/script/script_to_run.php

than goto start->run,
type in the path to cron.

pyro
10-10-2003, 02:25 PM
Awesome! Glad it's working for you... :) The cron is a bit different from a linux one, but close...