开发者

cronjob delaying based on PHP output

I'm in charge of a printer, so I wrote a script which runs every 5 开发者_开发问答minutes and figures out if the printer has paper. If it doesn't, the script will text me. The problem is, if I'm busy, and can't fill the printer, I don't want the script to continue to text me every 5 minutes. Is there a way I can force it to only send me at most 1 text every 8 hours or so, to ensure that the script doesn't text me twice for the same out-of-paper situation? The only thing I can currently think of is to create a db of times that I get texts, then make sure that the most recent one wasn't too long ago, or to create a local file with the most recent time in it.

Thanks!


You need to store somewhere the fact that it has text you and when this last occurred. You could do this using a plain file and by reading the files modification date to see when the text was last sent or you can use a database.


Assuming that the script that sends the SMS is PHP, use something like this. Can probably find a cleaner way of doing this, but this is just to show you the logic that is needed.

<?

/*
 * Replace outOfPaper() / sendSms() with the actual logic of your script
 */
$statusFile = './lastsms';

if(outOfPaper() && (is_file($statusFile) && (filemtime($statusFile) < time()-((8*60)*60)))){
    sendSms('+4412345678','Printer out of paper');
    touch($statusFile);
}

?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜