Reputation: 333
I want to send a report from a website to the owner using an email containing the number of total views of the website and the number of views from that week, being that data stored in a .txt file. How can I make my app send an email, lets say... every 7 days? ATM I have the code bellow in my afterFilter
in my AppController, it was taken from a views counter toturial, and striped of the number->image association, since it displayed the numbers with images. ATM, his should only count the total views.
I am using CakePHP 2.4.4.
afterFilter
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);
}
Upvotes: 0
Views: 2151
Reputation: 1321
You can use crontab
It's an Unix task Scheduler
With cron, you can periodically call a php script for send emails ;)
Example :
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"
Upvotes: 3