sniperscope Posted September 5, 2009 Share Posted September 5, 2009 Hi, My code running by cron tab. So, Cron executing file every min. when i test it i figured out that actually cron running more then once, this is weird because it suppose to run file and check the txt file if it is same then stop execution. I have 126 records in my list but if i check the db i see cron send mail more then 8 times. I do not what to do and even what makes this problem. <?php include('../../Cn/inc.php'); mysql_select_db($database, $cn); require_once('jcode.php'); include("Mail.php"); $GetLastRecord = mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT 1", $cn) or die(mysql_error()); $RowLastRecord = mysql_fetch_assoc($GetLastRecord); $LastRecordId = $RowLastRecord['id']; $Path = "../Rec.txt"; $Open = fopen($Path,"r"); $Read = fgets($Open); fclose($Open); if($Read != $LastRecordId){ $Ropen = fopen($Path,"w"); $Write = fwrite($Ropen, $LastRecordId); fclose($Ropen); // it should write and then close the file to prevent cron never run // this part of script one minute later. $LastRecordTitle = $RowLastRecord['title']; $LastRecordBody = $RowLastRecord['body']; $crr_date = date("Y/m/d H:m:s"); $mailFrom = "[email protected]"; $smtpinfo["host"] = "smtp.example.com"; $smtpinfo["port"] = "587"; $smtpinfo["auth"] = true; $smtpinfo["username"] = "info"; $smtpinfo["password"] = "123456"; $MailList = mysql_query("SELECT mail FROM list WHERE flg='0'", $cn) or die(mysql_error()); $RowList = mysql_fetch_assoc($MailList); $i = 0; do{ $mailTo = $RowList['mail']; $mailSubject = $LastRecordTitle; $returnMailAddress = $mailFrom; $tm =date("H:i"); $recipients = $mailTo; $headers["From"] = "[email protected]"; $headers["To"] = $mailTo; $headers["Subject"] = "=?iso-2022-jp?B?".base64_encode(mb_convert_encoding($LastRecordTitle,"JIS","SHIFT_JIS"))."?="; $headers["Return-Path"] = "[email protected]"; $headers["MIME-Version"] = "1.0"; $headers["Content-Type"] = "text/plain; charset=iso-2022-jp"; $mailmsg = mb_convert_encoding($LastRecordBody,"JIS","SHIFT_JIS"); $mail_object =& Mail::factory("smtp", $smtpinfo); $mail_object->send($recipients, $headers, $mailmsg); if($i == 60){ sleep(240); $smtpinfo["host"] = "smtp.example.com"; $smtpinfo["port"] = "587"; $smtpinfo["auth"] = true; $smtpinfo["username"] = "info"; $smtpinfo["password"] = "123456"; $i = 0; } $i++; } while($RowList = mysql_fetch_array($MailList)); } ?> Link to comment https://forums.phpfreaks.com/topic/173210-why-cron-run-twice/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.