Jump to content

Checking File Modified Timestamp


bschultz

Recommended Posts

I need to check a file's timestamp (last modified) and if it's BEFORE 15 minutes past the current hour (xx:15:00) then run a shell command.

 

Here's the code

 

<?php

///////// start of time constants /////////
date_default_timezone_set('US/Central');
$fullyear = date('Y');
$year = date('y');
$month = date('m');
$day = date('d');
$now = date('Y-m-d-h');
$hour = date('g');
$hourplus1 = date('g', strtotime("Now +1 hour"));
$hourminus1 = date('g', strtotime("Now -1 hour"));
$ampm = date('A');
$rename_date = date('mdg');
$nowis = date('m');

$copy1 = "/home/rpbroadcasting/audio/S$rename_date.mp3";


if (file_exists($copy1)) {
echo system('normalize-mp3 --mp3 '.escapeshellcmd($copy1));
    $stamp1 = date ("n-j-Y g:i:s A.", filemtime($copy1));
$fifteenpastthishour = mktime(date("n"), date("j"), date("y"), date("g"), 15);
if ($stamp1 <= $fifteenpastthishour)
{
echo system(escapeshellcmd("mp3gain -g 3 $copy1"));
}
}

$copy2 = "/home/rpbroadcasting/audio/N$rename_date.mp3";
if (file_exists($copy2)) {
echo system('normalize-mp3 --mp3 '.escapeshellcmd($copy2));
    $stamp2 = date ("n-j-Y g:i:s A.", filemtime($copy2));
$fifteenpastthishour = mktime(date("n"), date("j"), date("y"), date("g"), 15);
if ($stamp2 <= $fifteenpastthishour)
{
echo system(escapeshellcmd("mp3gain -g 1 $copy2"));
}
}

$copy3 = "/home/rpbroadcasting/audio/W$rename_date.mp3";
if (file_exists($copy3)) {
echo system('normalize-mp3 --mp3 '.escapeshellcmd($copy3));
    $stamp3 = date ("n-j-Y g:i:s A.", filemtime($copy3));
$fifteenpastthishour = mktime(date("n"), date("j"), date("y"), date("g"), 15);
if ($stamp3 <= $fifteenpastthishour)
{
echo system(escapeshellcmd("mp3gain -g 1 $copy3"));
}
}

?>

 

The problem is, it's ALWAYS running the mp3gamin shell command...no matter what the timestamp of the file is.

 

Where am I going wrong with this?

 

Thanks.

 

Brian

Link to comment
Share on other sites

Thanks for the help!

 

After re-thinking this, I need to make sure that the mp3gain command only runs once per hour.  I think I'll have to store the count in a flat file...and compare the count.  Then, I won't have to compare the timestamp...

 

Thanks again, though!

Link to comment
Share on other sites

The script to download these mp3's runs at xx:05:xx of each hour (via cron) ...and then checks if the file exists every five minutes after that (xx:10:00, xx:15:xx, xx:20:xx...etc) to accommodate a file not being present on the remote server at xx:05:xx of the hour.

 

The normalize script (also runs via cron) also needs to run every five minutes...to accommodate a file not being present on the remote server at xx:05:xx of the hour....but I only want to normalize the mp3 file once in the hour...not every five minutes that the file exists...so was going to check the timestamp.

 

Then, I realized that method wouldn't work either...if the file downloaded after 15 minutes past the hour...it would normalize every five minutes.  So...that's why I went with a flat file and a counter on that file.

 

<?php

///////// start of time constants /////////
date_default_timezone_set('US/Central');
$fullyear = date('Y');
$year = date('y');
$month = date('m');
$day = date('d');
$now = date('Y-m-d-h');
$hour = date('g');
$hourplus1 = date('g', strtotime("Now +1 hour"));
$hourminus1 = date('g', strtotime("Now -1 hour"));
$ampm = date('A');
$rename_date = date('mdg');
$nowis = date('m');

$copy1 = "/home/rpbroadcasting/audio/S$rename_date.mp3";
if (file_exists($copy1)) {
$fp = fopen("/var/www/sportscount.txt", "r");
$count = fread($fp, 1024);
fclose($fp);
$count = $count + 1;
if ($count == 1)
{
echo system('normalize-mp3 --mp3 '.escapeshellcmd($copy1));
echo system(escapeshellcmd("mp3gain -g 3 $copy1"));
//$count = 0;
echo "Count is 1...I have to normalize\n";
}
$fp = fopen("/var/www/sportscount.txt", "w");
fwrite($fp, $count);
fclose($fp);
}





$copy2 = "/home/rpbroadcasting/audio/N$rename_date.mp3";
if (file_exists($copy2)) {
$fp = fopen("/var/www/newscount.txt", "r");
$count = fread($fp, 1024);
fclose($fp);
$count = $count + 1;
if ($count == 1)
{
echo system('normalize-mp3 --mp3 '.escapeshellcmd($copy2));
echo system(escapeshellcmd("mp3gain -g 1 $copy2"));
//$count = 0;
echo "Count is 1...I have to normalize\n";
}
$fp = fopen("/var/www/newscount.txt", "w");
fwrite($fp, $count);
fclose($fp);
}







$copy3 = "/home/rpbroadcasting/audio/W$rename_date.mp3";
if (file_exists($copy3)) {
$fp = fopen("/var/www/weathercount.txt", "r");
$count = fread($fp, 1024);
fclose($fp);
$count = $count + 1;
if ($count == 1)
{
echo system('normalize-mp3 --mp3 '.escapeshellcmd($copy3));
echo system(escapeshellcmd("mp3gain -g 1 $copy3"));
//$count = 0;
echo "Count is 1...I have to normalize\n";
}
$fp = fopen("/var/www/weathercount.txt", "w");
fwrite($fp, $count);
fclose($fp);
}

?>

 

The above is working as I want it to...then I run another (via cron) script at the the top of the hour to reset the counts to 0.

 

Thanks again everyone!

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.