dannyd Posted February 29, 2008 Share Posted February 29, 2008 I wrote a cron script in PHP. Whenever the script runs the first time it inserts the data from files to database. But once there is data is in the database the script wont insert new data anymore. What could be the problem ? Quote Link to comment Share on other sites More sharing options...
wobbit Posted February 29, 2008 Share Posted February 29, 2008 Hi Danny, Can you supply us with your DB schema and the cron file. It might not be inserting due to duplication primary keys. But we can only guess without seeing your code Wob. Quote Link to comment Share on other sites More sharing options...
dannyd Posted February 29, 2008 Author Share Posted February 29, 2008 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. Quote Link to comment Share on other sites More sharing options...
wobbit Posted February 29, 2008 Share Posted February 29, 2008 Hi Danny, Like I said above, it's difficult for us to help you without anything to look at. Wob. Quote Link to comment Share on other sites More sharing options...
dannyd Posted February 29, 2008 Author Share Posted February 29, 2008 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 Quote Link to comment Share on other sites More sharing options...
dannyd Posted February 29, 2008 Author Share Posted February 29, 2008 Did that not help ? Anyone at all ??? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.