info('Start CallCloseAPI...'); ini_set('max_execution_time', Config::get('arrays.PHPTimeOutCL')); ini_set('max_input_time', Config::get('arrays.PHPTimeOutCL')); ini_set('default_socket_timeout', Config::get('arrays.PHPTimeOutCL')); ini_set('memory_limit', '1024M'); try { $this->info("Start Delete Old Labels Command..."); Log::channel('dailyCron')->info("Cron...Start Delete Old Labels Command..."); $labelsDirectoryTmp = '/www/sentm3live/htdocs/labels/'; $subFolders = ['CarrierLabel/','ContentLabel/','PackingList/']; // ,'CarrierLabel/','ContentLabel','PackingList','' $daysOld = 180; // Number of days to consider a file old : 180 =Six Months $filesToDeleteArr = []; foreach ($subFolders as $key => $subFolder) { $labelsDirectory = $labelsDirectoryTmp.$subFolder; $this->info("Getting Files From Directory: ".$labelsDirectory); Log::channel('dailyCron')->info("Getting Files From Directory: ".$labelsDirectory); exec('find '.$labelsDirectory.' -ctime +180 -type f -exec rm {} \;'); # exec('find '.$labelsDirectory.' -ctime +190 -type f -print | wc -l'); } $labelsFolder = $labelsDirectoryTmp; # Get Files from the specified Directory $filesToDelete = File::allFiles($labelsFolder); foreach ($filesToDelete as $file) { $lastAccessTime = new \DateTime("@".$file->getATime()); $now = new \DateTime(); $diff = $now->diff($lastAccessTime)->days; if ($diff >= $daysOld) { $this->info("File: ".$file." is Days Old: ".$diff); // Log::channel('dailyCron')->info("File: ".$file." is Days Old: ".$diff); # Add the File to Array $filesToDeleteArr[] = $file; } } // $this->info("Files to Delete..."); // dump($filesToDeleteArr); # Delete Old Files File::delete($filesToDeleteArr); Log::channel('dailyCron')->info("Cron...End Delete Old Labels Command..."); $this->info("End Delete Old Labels Command..."); } catch (\Throwable $th) { // Log::error($th); Log::channel('dailyCron')->error($th); } } }