Jump to content

How to modify script so I can pass it time to start rather then current time?


ghurty

Recommended Posts

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;

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;

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.