From: Roland Häder Date: Mon, 28 Apr 2014 14:03:32 +0000 (+0200) Subject: Added flushCheckPointFile(). X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=269780b35747a02770a68f9e70171c0f3b4b6a0b;p=core.git Added flushCheckPointFile(). Signed-off-by: Roland Häder --- 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;