Use a serialized array and store it in a flat text file if you're looking for something really simple and non-critical (otherwise I'd recommend using a mySQL table).
It could work like this:
<?php
class DailyVisitors {
protected $today, $statsFilePath, $dailyVisitors;
function __construct(){
$this->today = date('Y-m-d');
// A hidden file is more secure, and we use the year and month to prevent the file from bloating up over time, plus the information is now segmented by month
$this->statsFilePath = '.dailystats-' . date('Y-m-d');
// Load the file, but if it doesn't exists or we cannot parse it, use an empty array by default
$this->dailyVisitors = file_exists(statsFilePath) ? (unserialize(file_get_contents($statsFilePath)) ?: []) : [];
// We store the daily visitors as an array where the first element is the visit count for a particular day and the second element is the Unix timestamp of the time it was last updated
if(!isset($this->dailyVisitors[$this->today])) $this->dailyVisitors[$this->today] = [0, time()];
}
function increment(){
$dailyVisitors[$this->today][0] ++;
$dailyVisitors[$this->today][1] = time();
file_put_contents($this->statsFilePath, serialize($this->dailyVisitors)));
}
function getCount($date = null){
if(!$date) $date = $this->today; // If no date is passed the use today's date
$stat = $this->dailyVisitors[$date] ?: [0]; // Get the stat for the date or otherwise use a default stat (0 visitors)
return $stat[0];
}
}
$dailyVisitors = new DailyVisitors;
// Increment the counter for today
$dailyVisitors->increment();
// Print today's visit count
echo "Visitors today: " . $dailyVisitors->getCount();
// Print yesterday's visit count
echo "Visitors yesterday: " . $dailyVisitors->getCount(date('Y-m-d', strtotime('yesterday')));
I'm not sure there's any need to only display the data every 10 minutes, as you've to update it every time there's a new visitor anyway, and the unserializing of the data is pretty fast (in the single digit milliseconds range), but if for some reason you need to, you can just the timestamp (2nd element of the array of each day) to determine whether to upload a separate cache file that only stores the visit count for a particular day, using a modulus 600 (10 minutes) on the timestamp (which is expressed in seconds since the Unix epoch).