PHP task scheduling

as4s1n

New Member
Messages
174
Reaction score
4
Points
0
I have a question about scheduling tasks.

If I have a task scheduled on a PHP page, but that page is never called/referenced, would it still run at the scheduled time?
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
How is it "scheduled"?

For a script to run, someone/thing has to envoke it. Called as a web page, run by the cron daemon, or called from another page/script.
 

as4s1n

New Member
Messages
174
Reaction score
4
Points
0
To this effect:
PHP:
$curDate = date('h');
$dateToRun = "12";
$run = 1;
 
if($curDate == $dateToRun && $run == 1) {
   # ... Run task ...
   # ... Set run to 0
}
 
Last edited:

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
There's nothing there to schedule a task -- all that code will do is keep the code from running except between midnight and one AM and noon and one PM if something else calls your PHP page. The code may never run, or it may run multiple times.

What you need to do is remove the time-sensitive code and set up a cron job to launch the PHP script instead. You can start by looking at this tutorial.
 
Top