Php Cron作业,用于检查页面是否有特定更改,如果有,则将()发送出去
我正在设置一个CRON来检测页面上的更改。我遇到的问题更多地指向服务器端,但我希望其他人查看代码,看看是否有任何明显的问题会阻碍CRON正常运行。CRON运行脚本并在某些时间独立工作,结果要么100%正确,要么邮件延迟,时间戳来自消息中的$nws_timestamp 通过浏览器运行脚本时,每次都能正常工作 剧本摘要; 读取一个保存有远程数据的文本文件,并将两者进行比较,只提取和修剪更新的日期和时间。如果不同,它会向几封电子邮件发送一封带有更新日期和时间的电子邮件 脚本的目的: 允许国家气象局在风暴事件期间更新天气简报时通知人员列表。(就像现在我们身上的热带风暴一样)Php Cron作业,用于检查页面是否有特定更改,如果有,则将()发送出去,php,email,cron,Php,Email,Cron,我正在设置一个CRON来检测页面上的更改。我遇到的问题更多地指向服务器端,但我希望其他人查看代码,看看是否有任何明显的问题会阻碍CRON正常运行。CRON运行脚本并在某些时间独立工作,结果要么100%正确,要么邮件延迟,时间戳来自消息中的$nws_timestamp 通过浏览器运行脚本时,每次都能正常工作 剧本摘要; 读取一个保存有远程数据的文本文件,并将两者进行比较,只提取和修剪更新的日期和时间。如果不同,它会向几封电子邮件发送一封带有更新日期和时间的电子邮件 脚本的目的: 允许国家气象局在风
已解决
我最后运行了一些测试,发现脚本运行得很好,并且运行脚本的位置和调用文件都没有问题
问题存在于cron中使用的mail()函数中,我已转到PHPMailer以在脚本中发送邮件,并登录到SMTP以发送邮件。每次都准时上班
感谢您的帮助,这里还有CRON:12,32,52****php-q/home/mindbr5/public\u html/site\u accounts/~obxairwaves\u com/CRON/nws\u brief.php您的CRON日志说什么?Machavity-我相信我没有访问日志的权限,var/log/CRON,它是一个共享服务器。如果有其他方法,请让我知道。支持人员向我发送了日志中行的副本。看起来它运行正常,没有错误。5月10日16:12:01 ecbiz66 crond[8198]:(mindbr5)CMD(php-q/home/mindbr5/public_html/site_accounts/~obxairwaves_com/cron/nws_brief.php)
<?
$source = file_get_contents('http://www.erh.noaa.gov/mhx/downloads/briefings/index.php');
$textfile = 'nws_brief.txt';
list($junk,$nws_timestamp) = explode("Updated: </td><td align=\"left\">",$source);
$nws_timestamp = substr("$nws_timestamp", 0, 26); //location of text on page
$nws_timestamp = str_replace("</td>", "", "$nws_timestamp");
$nws_timestamp = str_replace("</tr>", "", "$nws_timestamp");
$nws_timestamp = str_replace("<", "", "$nws_timestamp");
$nws_timestamp = str_replace("/", "", "$nws_timestamp");
$nws_timestamp = str_replace("/t", "", "$nws_timestamp");
$nws_timestamp = str_replace("td", "", "$nws_timestamp");
$nws_timestamp = str_replace("d>", "", "$nws_timestamp");
$nws_timestamp = str_replace(">", "", "$nws_timestamp");
$textfile_data = file_get_contents($textfile);
//READ FROM FILE
if ($textfile_data == $nws_timestamp){
exit;
}else{
//Continue
}
//SAVE TO FILE
$current = file_get_contents($textfile);
$current = "$nws_timestamp";
file_put_contents($textfile, $current);
//EMAIL NOTIFICATION
//BCC List:
$bcc_list = array(
"user2@domain.com",
"user3@domain.com",
"user4@domain.com",
"user5@domain.com",
);
$bcc = implode(',', $bcc_list);
putenv('TZ=America/New_York');
$date_time = date('m-d-Y g:i:s A');
$to = "user1@domain.com";
$headers = "From: OBXAirWaves <admin@obxairwaves.com>\r\n";
$headers .= "Organization: OBXAirWaves.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "BCC: $bcc\r\n";
$subject = "NWS Briefing Update - $nws_timestamp";
$msg = "NWS Update - $date_time<br>
<a href=\"http://www.erh.noaa.gov/mhx/downloads/briefings/index.php \">Download Latest Briefing</a><br>
<br>
Briefing Update:<br>
<table border='1'>
<tr>
<td>New: $nws_timestamp</td>
</tr>
<tr>
<td>Last: $textfile_data</td>
</tr>
</table>
";
mail($to, $subject, $msg, $headers);
echo "Date & Time: $date_time<br>To: $to<br>BCC: $bcc<br>Subject: $subject<br><br>Message: <br>$msg";
?>