<?php //Description: When activated this script will remove any old entries from db.txt. function dbcleaner(string $dir) //Cleans db files from old data. { $curr_time = date("h:i:s",strtotime('-15 seconds')); //Stores the current time minus the a certain amount of time. $db_file = file($dir); //Accesses a db text file and stores each line into an array. $db_fsize = count($db_file); //Get the size of the db_file array. $db_change = False; //Boolian used to indicate if the file had to be changed. for($i = 0;$i < $db_fsize; $i++) //Loop that will iterate through the db array. { $decode = json_decode($db_file[$i]); //Gets the jsons stored in db_file and decodes them. if(date("h:i:s",strtotime($decode->inTime)) < date("h:i:s",strtotime($curr_time))) //Compares if the inTime of stored in each json is less than the one in the time variable. { unset($db_file[$i]); //Removes the json in db_file[i]. $db_change = True; //Indicates that their was change in db_file. } } if ($db_change == True) //Check if there was a change in db_file. { file_put_contents($dir, $db_file); //Rewrites the db.txt with the contents of db_file. } } date_default_timezone_set('America/Puerto_Rico'); //Changes the default timezone of the script to Puerto Rico. dbcleaner('/var/www/html/db.txt'); dbcleaner('/var/www/html/db2.txt'); ?>