Jump to content

strange cron problem - written in PHP


dannyd

Recommended Posts

I figured out the cron runs ONLY on the commandline. I read in a few places that i have to set my evironment variables but I dont know how to do that. i looked at similar crons but they dont seem to include anything different. My crontab is setup correctly not sure whats wrong.

 

 

Below is the script minus the connection string.

 

#!/usr/local/bin/php -q

 

<?PHP

 

///data base connection string removed for security

 

//loop through the last 3 days

 

for ($i=1;$i<30;$i++) {

     

  //$today = date("ydm");

     

  $pastdate = mktime(0,0,0,date("m"),date("d")-$i,date("Y"));

  $pastdate = date("ydm", $pastdate);

 

  $CURRENT_YEAR = substr($pastdate,0,2); //08

          $DAY  = substr($pastdate,2,2); //15

          $CURRENT_MONTH  = substr($pastdate,4,2); //02

 

           

 

 

$date = $CURRENT_YEAR . '-' . $CURRENT_MONTH . '-' . $DAY;

 

//log file date

$filedate = $CURRENT_YEAR . $DAY . $CURRENT_MONTH;

$filename = $filedate . 'log.txt';   

           

echo 'Processing the following files:<BR>';

                          echo $filename  . '<BR>';

 

 

$rundir = "/logs/";

$dir = opendir($asrundir);

 

                     

//parse contents in file

                        $file_handle = file_get_contents($rundir . $filename);

   

                  // Explodes .txt file into lines (\n)

                  $Lines = explode("\n",$file_handle);

                  array_shift($Lines); 

       

        //display fields from file

                    foreach($Lines as $Line) {

                   

if(!empty($Line)){       

$Line = preg_replace('/\s\s+/', ' ', trim($Line));

                    $fields = explode(" ",$Line);

 

               

//date-time formatting

$newtime = $fields[1];

            $time = substr($newtime,-6);

                              $hours    = $time[0].$time[1];

                                $minutes  = $time[2].$time[3];

$seconds    = $time[4].$time[5];

                                        $time = $hours . ':' . $minutes . ':' . $seconds;

                   

                                        //values to be inserted into asrunlogs table

//datetime

$datetime = $date . ' ' . $time;

//length of item

                   

//$length = preg_replace("/^0*/",'', $fields[2]);

$length = $fields[2];

$min = substr($length,2,2);

                                        $sec = substr($length,4,2);

$length = ($min*60) + $sec;

 

 

//creative id

$creative = $fields[3];

                   

                           

$addsql ="REPLACE INTO logs (airtime,length,creative) values ('$datetime', '$length','$creative')";

$add = mysql_query($addsql);

 

               

}

   

                }

 

               

    }

 

  fclose ($dir);

  exit ();   

?>

 

DB Schema:

 

Logs

-------

Airtime

Length

Creative

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.