ghurty Posted January 22, 2010 Share Posted January 22, 2010 I currently have this script that builds file names based on current time plus 2 ($spread variable) minutes. It continues to create files until it finishes the sql table. it creates numerous files per time frame based on how that the $maxlines variable is set to. How would I modify it so that I can pass on the variable $starttime and it will start generating based on that start time rather then the current time. I tried getting rid of lines 2,3,4 and replacing it will $calltime equals the time that is passed to the script, however that only worked for the first file it generated, and not for the other ones. Thanks $spread=1 ; $thisminute = date("i") ; $calltime = date("Hi",mktime(date("H"),$thisminute+2,0,date("m"),date("d"),date("Y"))) ; $mincounter = 2 ; $loopcounter = 1 ; while ($row = mysql_fetch_array($result)) { $id = $row["id"] ; $thisfile = $calltime . $loopcounter . ".txt" ; $fromfile = "/tmp/" . $thisfile ; $tofile = "/tmp2/" . $thisfile ; $fptmp = fopen($fromfile, "w"); fclose($fptmp) ; $tz = getdate(); $tz['hours'] = substr( $calltime, 0, 2 ); $tz['minutes'] = substr( $calltime, 2, 2 ); $time_now = time( ); $time2call = mktime( substr( $calltime, 0, 2 ), substr( $calltime, 2, 2 ), 0, $tz[mon], $tz[mday], $tz[year] ); if ( $time2call <= $time_now ) $time2call += 86400; //touch($fromfile, $time2call, $time2call); touch($fromfile, $time2call); $copyok = copy($fromfile,"/tmp/tmp.txt") ; $moveok = rename($fromfile,$tofile); // fixed: if curr minute does not equal last minute calc then subtract one from calculation below if ($loopcounter == $maxlines) : $thisminute2 = date("i") ; if ($thisminute <> $thisminute2) : $mincounter = $mincounter + spread - 1 ; else : $mincounter = $mincounter + spread ; endif ; $calltime = date("Hi",mktime(date("H"),$thisminute2+$mincounter,0,date("m"),date("d"),date("Y"))) ; $thisminute = $thisminute2 ; $loopcounter = 1 ; else : $loopcounter = $loopcounter + 1 ; endif ; } mysql_close($link); // clean up file handlers etc. fclose($stdin); fclose($stdout); fclose($stdlog); exit; Quote Link to comment Share on other sites More sharing options...
ghurty Posted January 22, 2010 Author Share Posted January 22, 2010 I noticed that I left out some "$" by the "spread" a few times, but in my script I have them Quote Link to comment Share on other sites More sharing options...
ghurty Posted January 22, 2010 Author Share Posted January 22, 2010 Here it is with the corrections: $spread=1 ; $thisminute = date("i") ; $calltime = date("Hi",mktime(date("H"),$thisminute+2,0,date("m"),date("d"),date("Y"))) ; $mincounter = 2 ; $loopcounter = 1 ; while ($row = mysql_fetch_array($result)) { $id = $row["id"] ; $thisfile = $calltime . $loopcounter . ".txt" ; $fromfile = "/tmp/" . $thisfile ; $tofile = "/tmp2/" . $thisfile ; $fptmp = fopen($fromfile, "w"); fclose($fptmp) ; $tz = getdate(); $tz['hours'] = substr( $calltime, 0, 2 ); $tz['minutes'] = substr( $calltime, 2, 2 ); $time_now = time( ); $time2call = mktime( substr( $calltime, 0, 2 ), substr( $calltime, 2, 2 ), 0, $tz[mon], $tz[mday], $tz[year] ); if ( $time2call <= $time_now ) $time2call += 86400; //touch($fromfile, $time2call, $time2call); touch($fromfile, $time2call); $copyok = copy($fromfile,"/tmp/tmp.txt") ; $moveok = rename($fromfile,$tofile); // fixed: if curr minute does not equal last minute calc then subtract one from calculation below if ($loopcounter == $maxlines) : $thisminute2 = date("i") ; if ($thisminute <> $thisminute2) : $mincounter = $mincounter + $spread - 1 ; else : $mincounter = $mincounter + $spread ; endif ; $calltime = date("Hi",mktime(date("H"),$thisminute2+$mincounter,0,date("m"),date("d"),date("Y"))) ; $thisminute = $thisminute2 ; $loopcounter = 1 ; else : $loopcounter = $loopcounter + 1 ; endif ; } mysql_close($link); // clean up file handlers etc. fclose($stdin); fclose($stdout); fclose($stdlog); exit; 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.