您的主机可能会在您的主机控制面板中提供 cron 功能。我使用它的几次,我发现这是一种将要在服务器上运行的文件的路径然后从几个下拉菜单中选择频率的情况。从那里你走了..
至于解决方案,你可以作为一个非常简单的例子......
cron.php
<?php
/*
Steps
1 - Set any completed tasks to done
2 - Check if users need to be notified and send the notifications
*/
function send_notifications($email,$time_ends){
// insert code here to deal with sending the notification to the iphone
}
include("db.php"); // contains your MySQL connection vars or whatnot
// STEP 1 - Set any completed tasks to done
$update_db = mysql_query("UPDATE Notifications SET complete = '1' WHERE time_completed > '0000-00-00 00:00:00'");
// STEP 2 - Send any outstanding notifications out
$result = mysql_query("SELECT * FROM Notifications WHERE time_completed = '0000-00-00 00:00:00'"); // add another where clause to prevent bombarding with notifications for example " AND notification_2_days = '0'"
while($row = mysql_fetch_array($result))
{
send_notifications($row['email'],$row['time_ends']);
// insert an update query here to flag as a notification sent, you dont want to bombard
}
?>
警告 - 为了简单起见,这是使用折旧的连接代码(查找 MySQL PDO 等),这缺乏任何类型的安全性。