我想使用一封电子邮件从网站向所有者发送报告,该电子邮件包含网站的总观看次数和该周的观看次数,即存储在.txt文件中的数据。如何让我的应用发送电子邮件,让我们说每7天一次? ATM我在我的AppController中的afterFilter
下面有代码,它是从视图计数器中获取的,并且是数字 - >>图像关联的条带,因为它显示带有图像的数字。 ATM,他应该只计算总观看次数。
我正在使用CakePHP 2.4.4。
后过滤
session_start();
$counter = $this->webroot."counter.txt";
// Check if a text file exists. If not create one and initialize it to zero.
if (!file_exists($counter)) {
$f = fopen($counter, "w");
fwrite($f,"0");
fclose($f);
}
// Read the current value of our counter file
$f = fopen($counter,"r");
$counterVal = fread($f, filesize($counter));
fclose($f);
// Has visitor been counted in this session?
// If not, increase counter value by one
if(!isset($_SESSION['hasVisited'])){
$_SESSION['hasVisited']="yes";
$counterVal++;
$f = fopen($counter, "w");
fwrite($f, $counterVal);
fclose($f);
}
$counterVal = str_pad($counterVal, 5, "0", STR_PAD_LEFT);
}
答案 0 :(得分:3)
您可以使用crontab
这是一个Unix任务调度程序
使用cron,您可以定期调用php脚本发送电子邮件;)
示例:
01 * * * * root echo "This command is run at one min past every hour"
17 8 * * * root echo "This command is run daily at 8:17 am"
17 20 * * * root echo "This command is run daily at 8:17 pm"
00 4 * * 0 root echo "This command is run at 4 am every Sunday"
* 4 * * Sun root echo "So is this"
42 4 1 * * root echo "This command is run 4:42 am every 1st of the month"
01 * 19 07 * root echo "This command is run hourly on the 19th of July"