基于 PHP 输出的 cronjob 延迟
我负责一台打印机,所以我编写了一个脚本,每 5 分钟运行一次,并确定打印机是否有纸。如果没有,脚本会给我发短信。问题是,如果我很忙,无法填满打印机,我不希望脚本继续每 5 分钟给我发一条短信。有没有办法强制它每 8 小时左右最多只向我发送 1 条短信,以确保脚本不会在相同的缺纸情况下向我发送两次短信?我目前唯一能想到的就是创建一个接收文本时间的数据库,然后确保最近的一次不是很久以前,或者创建一个包含最近时间的本地文件。
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在某处存储以下事实:它包含您的文本以及上次发生这种情况的时间。您可以使用纯文件并通过读取文件修改日期来查看文本上次发送的时间,或者可以使用数据库来执行此操作。
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.
假设发送短信的脚本是 PHP,请使用类似以下内容。
可能可以找到一种更简洁的方法来执行此操作,但这只是为了向您展示所需的逻辑。
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.