$GLOBALS['current_hash'], 'root_hash' => $GLOBALS['root_hash'], 'nonce' => (float) $GLOBALS['nonce'], 'iter' => $GLOBALS['iteration'], 'hashes_block' => $GLOBALS['hashes_block'], 'hash_cycles' => $GLOBALS['hash_cycles'], 'difficulty' => $GLOBALS['difficulty'], 'nonce_hash' => $hash, ]); // Found hash: print ('FOUND: hash=' . $hash . ',nonce=' . $GLOBALS['nonce'] . ',total_found=' . $GLOBALS['total_found'] . PHP_EOL); // Set time as a new hash was found $GLOBALS['found_time'] = microtime(true); // Flush check-point file after new hash is found flushCheckPointFile($hash); } /** * Initializes nonce * * @return void */ function initNonce () { $GLOBALS['nonce'] = 1 / (mt_rand() ^ (1 / pi())); print (__FUNCTION__ . ': nonce=' . $GLOBALS['nonce'] . PHP_EOL); } /** * Sums all hex parts of the hash to one final sum * * @param $hash Hex-hash to sum * @return Sum of hash */ function sumHash ($hash) { // Init it $sum = 0; for ($i = 0; $i < (strlen($hash) / 2); $i++) { $sum += hexdec(substr($hash, $i, 2)); } return $sum; } /** * Loads check-point file, if found * * @return void */ function loadCheckpointFile () { // Is the check point there? if (is_readable(CHECKPOINT_FILE)) { // Then load it $checkPoint = file_get_contents(CHECKPOINT_FILE); // Explode it $data = explode('|', $checkPoint); // Assert on count assert(count($data) == 10); // 1st element is nonce, 2nd hash, 3rd found hashes $GLOBALS['total_blocks'] = $data[0]; $GLOBALS['total_reward'] = $data[1]; $GLOBALS['total_hashes'] = $data[2]; $GLOBALS['total_found'] = $data[3]; $GLOBALS['total_restarts'] = $data[4]; $GLOBALS['hash_cycles'] = intval($data[5]); $GLOBALS['salt'] = $data[6]; $GLOBALS['difficulty'] = $data[7]; $GLOBALS['nonce'] = (float) base64_decode($data[8]); $GLOBALS['current_hash'] = $data[9]; $GLOBALS['root_hash'] = $data[9]; $GLOBALS['found_hashes'] = json_decode(gzuncompress(base64_decode($data[11])), TRUE); } // END - if }