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;

Link to comment
Share on other sites

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;

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.