From 269780b35747a02770a68f9e70171c0f3b4b6a0b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 28 Apr 2014 16:03:32 +0200 Subject: [PATCH] Added flushCheckPointFile(). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- contrib/chash/chash.php | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/contrib/chash/chash.php b/contrib/chash/chash.php index 0e60d0fb..1bc7f147 100644 --- a/contrib/chash/chash.php +++ b/contrib/chash/chash.php @@ -10,6 +10,9 @@ define('CHECK_POINT', 'chash.pos'); // Found hashes $foundHashes = array(); +// Time when last flush occured +global $timeFlush; + /** * Continued-hashing * @@ -185,6 +188,24 @@ function calculateNonce ($nonce) { return $newNonce; } +/** + * Writes/flushes check-point file + * + * @return void + */ +function flushCheckPointFile ($nonce, $modulaHash, array $foundHashes) { + global $timeFlush; + + // Display message + print ('FLUSHING: ' . count($foundHashes) . ' total found.' . PHP_EOL); + + // Flush data + file_put_contents(CHECK_POINT, base64_encode($nonce) . ':' . $modulaHash . ':' . base64_encode(serialize($foundHashes))); + + // Set time + $timeFlush = microtime(TRUE); +} + /* * Calculate "genesis" hashes, please note that these "genesis strings" are now * known to the public as you can read them here in source code and therefore I @@ -328,13 +349,8 @@ while (TRUE) { // Only once per 10 seconds if ($testTime >= 10) { - // Display message - print ('FLUSHING: ' . count($foundHashes) . ' total found.' . PHP_EOL); - - // Write check-point - file_put_contents(CHECK_POINT, base64_encode($nonce) . ':' . $modulaHash . ':' . base64_encode(serialize($foundHashes))); - - $timeFlush = microtime(TRUE); + // Flush check-point file + flushCheckPointFile($nonce, $modulaHash, $foundHashes); } // END - if // Next round @@ -375,6 +391,8 @@ while (TRUE) { // Found hash: print ('FOUND: nonceHash=' . $nonceHash . ',nonce=' . $nonce . ',iter=' . $iter . PHP_EOL); + // Flush check-point file after new hash is found + flushCheckPointFile($nonce, $nonceHash, $foundHashes); // Use nonceHash as next modula hash $modulaHash = $nonceHash; -- 2.30.2