Moved mysqli_close after the optional loading of dead instances from the db; renamed $eta to $tet

This commit is contained in:
pezcurrel 2022-12-21 22:05:15 +01:00
parent 626a05b509
commit 1c524ffd69

View file

@ -63,6 +63,7 @@ DESCRIPTION
specifiable file (typically the output file from a peerscrawl.php run).
OPTIONS
-
Everything after a single dash will be passed to '.CHILD.' processes as is.
-p, --peersfp <file>
@ -215,7 +216,7 @@ if ($restore) {
$instk=$buf[0][1]+0;
$toff=$buf[0][2]+0;
$done=$buf[0][3]+0;
//eecho(0,'poolsize: '.$opts['poolsize'].'; instk: '.$instk.'; eta: '.$eta.'; done: '.$done.'.'.N);
//eecho(0,'poolsize: '.$opts['poolsize'].'; instk: '.$instk.'; eta: '.$tet.'; done: '.$done.'.'.N);
for ($i=1; $i<count($buf); $i++) {
if (preg_match('/^\d+$/',$buf[$i])!==1) mexit('file «'.$statusjfp.'»: wrong format (3).'.N,1,true);
//eecho(0,$i.': '.$buf[$i].'.'.N);
@ -248,9 +249,6 @@ if ($restore) {
$insts[]=$row['URI'];
eecho(1,'loaded '.count($insts).' known, alive instances from the database.'.N);
mysqli_close($link);
unset($link);
if (!is_null($opts['peersfp'])) {
eecho(0,'loading dead instances from the database...'.N);
$res=myq($link,'SELECT URI FROM Instances WHERE Dead=1',__LINE__);
@ -276,6 +274,9 @@ if ($restore) {
eecho(1,'loaded '.$i.' more instances from «'.$opts['peersfp'].'».'.N);
}
mysqli_close($link);
unset($link);
unset($deadinsts);
shuffle($insts);
$cinsts=count($insts);
@ -304,7 +305,7 @@ $tini=microtime(true);
$rundone=false;
do {
$now=microtime(true);
$eta=$now-$tini+$toff;
$tet=$now-$tini+$toff;
eecho(0,'[[[ CHECKING PROCESSES POOL ]]]'.N);
$somerun=false;
foreach ($procs as $key=>$proc) {
@ -330,11 +331,11 @@ do {
}
}
}
$out=$done.'/'.$cinsts.' ('.round(100/$cinsts*$done).'%); elapsed time: '.ght($eta);
if ($done>0) $out.='; estimated time remaining: '.ght($cinsts*$eta/$done-$eta);
$out=$done.'/'.$cinsts.' ('.round(100/$cinsts*$done).'%); elapsed time: '.ght($tet);
if ($done>0) $out.='; estimated time remaining: '.ght($cinsts*$tet/$done-$tet);
eecho(1,$out.'.'.N);
if ($somerun) {
writestatus($statusjfp,$opts,$instk,$eta,$done,$procs);
writestatus($statusjfp,$opts,$instk,$tet,$done,$procs);
sleep(1);
} else {
$rundone=true;
@ -351,10 +352,10 @@ exit(0);
// functions
function writestatus(&$statusjfp,&$opts,&$instk,&$eta,&$done,&$procs) {
function writestatus(&$statusjfp,&$opts,&$instk,&$tet,&$done,&$procs) {
$f=@fopen($statusjfp,'w');
if ($f===false) mexit('could not open «'.$statusjfp.'» for writing.'.N,2,true);
fwrite($f,$opts['poolsize']."\t".$instk."\t".$eta."\t".$done.N);
fwrite($f,$opts['poolsize']."\t".$instk."\t".$tet."\t".$done.N);
foreach ($procs as $proc)
if (!is_null($proc))
fwrite($f,$proc['instk'].N);