From 2dad4ee96e99084b28b5a3af1f7ba60ef84f69a0 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Thu, 29 Nov 2018 20:49:20 +0100 Subject: [PATCH] Use now() helper for calculating scripts runtime --- Blacklight/Backfill.php | 4 ++-- Blacklight/Binaries.php | 28 +++++++++++------------ Blacklight/Books.php | 4 ++-- Blacklight/Console.php | 4 ++-- Blacklight/libraries/Forking.php | 4 ++-- Blacklight/libraries/ForkingImportNZB.php | 4 ++-- Changelog | 1 + misc/testing/PostProc/getConsole.php | 4 ++-- misc/testing/PostProc/getGameCovers.php | 4 ++-- misc/testing/PostProc/getImdb.php | 4 ++-- misc/testing/PostProc/getMovieCovers.php | 2 +- misc/testing/PostProc/getXXXCovers.php | 4 ++-- 12 files changed, 34 insertions(+), 33 deletions(-) diff --git a/Blacklight/Backfill.php b/Blacklight/Backfill.php index bc5fdada4..365dff32c 100755 --- a/Blacklight/Backfill.php +++ b/Blacklight/Backfill.php @@ -168,7 +168,7 @@ class Backfill public function backfillGroup($groupArr, $left, $articles = ''): void { // Start time for this group. - $startGroup = microtime(true); + $startGroup = now()->timestamp; $this->_binaries->logIndexerStart(); @@ -318,7 +318,7 @@ class Backfill 'Group '. $groupName. ' processed in '. - number_format(microtime(true) - $startGroup, 2). + number_format(now()->timestamp - $startGroup, 2). ' seconds.' ); } diff --git a/Blacklight/Binaries.php b/Blacklight/Binaries.php index 47a213fd0..f2a90f28c 100755 --- a/Blacklight/Binaries.php +++ b/Blacklight/Binaries.php @@ -281,7 +281,7 @@ class Binaries $groupCount = \count($groups); if ($groupCount > 0) { $counter = 1; - $allTime = microtime(true); + $allTime = now()->timestamp; $this->log( 'Updating: '.$groupCount.' group(s) - Using compression? '.($this->_compressedHeaders ? 'Yes' : 'No'), @@ -301,7 +301,7 @@ class Binaries } $this->log( - 'Updating completed in '.number_format(microtime(true) - $allTime, 2).' seconds.', + 'Updating completed in '.number_format(now()->timestamp - $allTime, 2).' seconds.', __FUNCTION__, 'primary' ); @@ -334,7 +334,7 @@ class Binaries */ public function updateGroup($groupMySQL, $maxHeaders = 0): void { - $startGroup = microtime(true); + $startGroup = now()->timestamp; $this->logIndexerStart(); @@ -541,7 +541,7 @@ class Binaries if ($this->_echoCLI) { $this->colorCli->primary( PHP_EOL.'Group '.$groupMySQL['name'].' processed in '. - number_format(microtime(true) - $startGroup, 2).' seconds.' + number_format(now()->timestamp - $startGroup, 2).' seconds.' ); } } elseif ($this->_echoCLI) { @@ -570,7 +570,7 @@ class Binaries public function scan($groupMySQL, $first, $last, $type = 'update', $missingParts = null): array { // Start time of scan method and of fetching headers. - $this->startLoop = microtime(true); + $this->startLoop = now(); $this->groupMySQL = $groupMySQL; $this->last = $last; $this->first = $first; @@ -642,10 +642,10 @@ class Binaries } // Start of processing headers. - $this->startCleaning = microtime(true); + $this->startCleaning = now(); // End of the getting data from usenet. - $this->timeHeaders = number_format($this->startCleaning - $this->startLoop, 2); + $this->timeHeaders = $this->startCleaning->diffInSeconds($this->startLoop); // Check if we got headers. $msgCount = \count($headers); @@ -742,10 +742,10 @@ class Binaries unset($stdHeaders); // Start of part repair. - $this->startPR = microtime(true); + $this->startPR = now(); // End of inserting. - $this->timeInsert = number_format($this->startPR - $this->startUpdate, 2); + $this->timeInsert = $this->startPR->diffInSeconds($this->startUpdate); if ($partRepair && \count($headersRepaired) > 0) { $this->removeRepairedParts($headersRepaired, $this->tableNames['prname'], $this->groupMySQL['id']); @@ -933,10 +933,10 @@ class Binaries //unset($headers); // Reclaim memory. // Start of inserting into SQL. - $this->startUpdate = microtime(true); + $this->startUpdate = now(); // End of processing headers. - $this->timeCleaning = number_format($this->startUpdate - $this->startCleaning, 2); + $this->timeCleaning = $this->startUpdate->diffInSeconds($this->startCleaning); $binariesQuery = $binariesCheck = sprintf('INSERT INTO %s (id, partsize, currentparts) VALUES ', $this->tableNames['bname']); foreach ($binariesUpdate as $binaryID => $binary) { $binariesQuery .= '('.$binaryID.','.$binary['Size'].','.$binary['Parts'].'),'; @@ -1023,7 +1023,7 @@ class Binaries */ protected function outputHeaderDuration(): void { - $currentMicroTime = microtime(true); + $currentMicroTime = now(); if ($this->_echoCLI) { $this->colorCli->alternateOver($this->timeHeaders.'s'). $this->colorCli->primaryOver(' to download articles, '). @@ -1031,9 +1031,9 @@ class Binaries $this->colorCli->primaryOver(' to process collections, '). $this->colorCli->alternateOver($this->timeInsert.'s'). $this->colorCli->primaryOver(' to insert binaries/parts, '). - $this->colorCli->alternateOver(number_format($currentMicroTime - $this->startPR, 2).'s'). + $this->colorCli->alternateOver($currentMicroTime->diffInSeconds($this->startPR).'s'). $this->colorCli->primaryOver(' for part repair, '). - $this->colorCli->alternateOver(number_format($currentMicroTime - $this->startLoop, 2).'s'). + $this->colorCli->alternateOver($currentMicroTime->diffInSeconds($this->startLoop).'s'). $this->colorCli->primary(' total.'); } } diff --git a/Blacklight/Books.php b/Blacklight/Books.php index a24b65615..4e7e89644 100755 --- a/Blacklight/Books.php +++ b/Blacklight/Books.php @@ -475,7 +475,7 @@ class Books $bookId = -2; foreach ($res as $arr) { - $startTime = microtime(true); + $startTime = now()->timestamp; $usedAmazon = false; // audiobooks are also books and should be handled in an identical manor, even though it falls under a music category if ($arr['categories_id'] === '3030') { @@ -519,7 +519,7 @@ class Books } } // Sleep to not flood amazon. - $diff = floor((microtime(true) - $startTime) * 1000000); + $diff = floor((now()->timestamp - $startTime) * 1000000); if ($this->sleeptime * 1000 - $diff > 0 && $usedAmazon === true) { usleep($this->sleeptime * 1000 - $diff); } diff --git a/Blacklight/Console.php b/Blacklight/Console.php index 04c594e69..32ff4a9c5 100755 --- a/Blacklight/Console.php +++ b/Blacklight/Console.php @@ -925,7 +925,7 @@ class Console } foreach ($res as $arr) { - $startTime = microtime(true); + $startTime = now()->timestamp; $usedAmazon = false; $gameId = self::CONS_NTFND; $gameInfo = $this->parseTitle($arr['searchname']); @@ -971,7 +971,7 @@ class Console Release::query()->where('id', $arr['id'])->update(['consoleinfo_id'=> $gameId]); // Sleep to not flood amazon. - $diff = floor((microtime(true) - $startTime) * 1000000); + $diff = floor((now()->timestamp - $startTime) * 1000000); if ($this->sleeptime * 1000 - $diff > 0 && $usedAmazon === true) { usleep($this->sleeptime * 1000 - $diff); } diff --git a/Blacklight/libraries/Forking.php b/Blacklight/libraries/Forking.php index 343f74b3f..1476caf3d 100755 --- a/Blacklight/libraries/Forking.php +++ b/Blacklight/libraries/Forking.php @@ -181,7 +181,7 @@ class Forking extends \fork_daemon public function processWorkType($type, array $options = []) { // Set/reset some variables. - $startTime = microtime(true); + $startTime = now()->timestamp; $this->workType = $type; $this->workTypeOptions = $options; $this->processAdditional = $this->processNFO = $this->processTV = $this->processMovies = $this->ppRenamedOnly = false; @@ -201,7 +201,7 @@ class Forking extends \fork_daemon if (config('nntmux.echocli')) { $this->colorCli->header( - 'Multi-processing for '.$this->workType.' finished in '.(microtime(true) - $startTime). + 'Multi-processing for '.$this->workType.' finished in '.(now()->timestamp - $startTime). ' seconds at '.date(DATE_RFC2822).'.'.PHP_EOL ); } diff --git a/Blacklight/libraries/ForkingImportNZB.php b/Blacklight/libraries/ForkingImportNZB.php index 3d385d569..b408f9eb4 100755 --- a/Blacklight/libraries/ForkingImportNZB.php +++ b/Blacklight/libraries/ForkingImportNZB.php @@ -55,7 +55,7 @@ class ForkingImportNZB extends Forking */ public function start($folder, $maxProcesses, $deleteComplete, $deleteFailed, $useFileName, $maxPerProcess): void { - $startTime = microtime(true); + $startTime = now()->timestamp; $directories = glob($folder.'/*', GLOB_ONLYDIR); $this->_workCount = \count($directories); @@ -85,7 +85,7 @@ class ForkingImportNZB extends Forking if (config('nntmux.echocli')) { $this->colorCli->header( - 'Multi-processing for import finished in '.(microtime(true) - $startTime). + 'Multi-processing for import finished in '.(now()->timestamp - $startTime). ' seconds at '.date(DATE_RFC2822).'.'.PHP_EOL ); } diff --git a/Changelog b/Changelog index cae6eb927..fd1b6f61b 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-11-29 DariusIII + * Chg: Use now() helper for calculating scripts runtime * Chg: Simplify functions that check for mgrPoster variable * Chg: Update imdbphp/imdbphp to version 6.1.2 * Chg: Use DB::statement in place of DB::unprepared + DB::commit diff --git a/misc/testing/PostProc/getConsole.php b/misc/testing/PostProc/getConsole.php index d3c475f5c..cd606c271 100644 --- a/misc/testing/PostProc/getConsole.php +++ b/misc/testing/PostProc/getConsole.php @@ -25,7 +25,7 @@ if ($res instanceof \Traversable) { $colorCli->header('Updating console info for '.number_format($res->rowCount()).' releases.'); foreach ($res as $arr) { - $starttime = microtime(true); + $starttime = now()->timestamp; $gameInfo = $console->parseTitle($arr['searchname']); if ($gameInfo !== false) { $game = $console->updateConsoleInfo($gameInfo); @@ -35,7 +35,7 @@ if ($res instanceof \Traversable) { } // amazon limits are 1 per 1 sec - $diff = floor((microtime(true) - $starttime) * 1000000); + $diff = floor((now()->timestamp - $starttime) * 1000000); if (1000000 - $diff > 0) { $colorCli->alternate('Sleeping'); usleep(1000000 - $diff); diff --git a/misc/testing/PostProc/getGameCovers.php b/misc/testing/PostProc/getGameCovers.php index ceb48ef3c..4588c0f8e 100644 --- a/misc/testing/PostProc/getGameCovers.php +++ b/misc/testing/PostProc/getGameCovers.php @@ -19,7 +19,7 @@ if ($total > 0) { $colorCli->header('Updating game covers for '.number_format($total).' releases.'); foreach ($res as $arr) { - $starttime = microtime(true); + $starttime = now()->timestamp; $gameInfo = $game->parseTitle($arr['title']); if ($gameInfo !== false) { $colorCli->primary('Looking up: '.$gameInfo['release']); @@ -34,7 +34,7 @@ if ($total > 0) { } // amazon limits are 1 per 1 sec - $diff = floor((microtime(true) - $starttime) * 1000000); + $diff = floor((now()->timestamp - $starttime) * 1000000); if (1000000 - $diff > 0) { $colorCli->alternate('Sleeping'); usleep(1000000 - $diff); diff --git a/misc/testing/PostProc/getImdb.php b/misc/testing/PostProc/getImdb.php index d07a8b911..45cb4bde6 100644 --- a/misc/testing/PostProc/getImdb.php +++ b/misc/testing/PostProc/getImdb.php @@ -18,11 +18,11 @@ if ($movies instanceof \Traversable) { $colorCli->header('Updating movie info for '.number_format($count).' movies.'); foreach ($movies as $mov) { - $startTime = microtime(true); + $startTime = now()->timestamp; $mov = $movie->updateMovieInfo($mov['imdbid']); // tmdb limits are 30 per 10 sec, not certain for imdb - $diff = floor((microtime(true) - $startTime) * 1000000); + $diff = floor((now()->timestamp - $startTime) * 1000000); if (333333 - $diff > 0) { echo "sleeping\n"; usleep(333333 - $diff); diff --git a/misc/testing/PostProc/getMovieCovers.php b/misc/testing/PostProc/getMovieCovers.php index c8647a026..3cdba1711 100644 --- a/misc/testing/PostProc/getMovieCovers.php +++ b/misc/testing/PostProc/getMovieCovers.php @@ -15,7 +15,7 @@ $count = $movies->count(); if ($count > 0) { $colorCli->primary('Updating '.number_format($count).' movie covers.'); foreach ($movies as $mov) { - $startTime = microtime(true); + $startTime = now()->timestamp; $mov = $movie->updateMovieInfo($mov['imdbid']); } } else { diff --git a/misc/testing/PostProc/getXXXCovers.php b/misc/testing/PostProc/getXXXCovers.php index eefbbb421..d8f5244ec 100644 --- a/misc/testing/PostProc/getXXXCovers.php +++ b/misc/testing/PostProc/getXXXCovers.php @@ -13,11 +13,11 @@ $movies = DB::select('SELECT title FROM xxxinfo WHERE cover = 0'); echo $c->primary('Updating '.number_format(\count($movies)).' XXX movie covers.'); foreach ($movies as $mov) { - $starttime = microtime(true); + $starttime = now()->timestamp; $mov = $movie->updateXXXInfo($mov->title); // sleep so that it's not ddos' the site - $diff = floor((microtime(true) - $starttime) * 1000000); + $diff = floor((now()->timestamp - $starttime) * 1000000); if (333333 - $diff > 0) { echo "\nsleeping\n"; usleep(333333 - $diff);