Skip to content

Instantly share code, notes, and snippets.

@ety001
Created February 3, 2018 03:48
Show Gist options
  • Select an option

  • Save ety001/eece615a27fef8c26c762e34fdb2d781 to your computer and use it in GitHub Desktop.

Select an option

Save ety001/eece615a27fef8c26c762e34fdb2d781 to your computer and use it in GitHub Desktop.
<?php
$pdo = null;
function DBConnect() {
global $pdo;
$pdo = new PDO('mysql:host=mysql.steem-lightdb.com;dbname=steem;port=3306','steemit','steemit');
$pdo->exec('set names utf8');
}
function DBClose() {
global $pdo;
$pdo = null;
}
function DBBlockNum() {
global $pdo;
$stmt = $pdo->prepare("select block_num from sbds_core_blocks order by block_num desc limit 1");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
return $rows[0]['block_num'];
}
function BlockMissing($max) {
global $pdo;
$chunk = 100000;
$num_chunks = (int)($max / $chunk) + 1;
$start = 1;
$missing = [];
for($i=1; $i <= $num_chunks; $i++) {
if ($i == 1) {
$start = 1;
} else {
$start = $end;
}
$end = $start + $chunk;
$stmt = $pdo->prepare("select block_num from sbds_core_blocks where block_num >= ".$start." and block_num < ".$end);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
$stmt->closeCursor();
$period_nums = range(start, $end-1);
$tmp_missing = array_diff($period_nums, $rows);
$missing = array_merge($missing, $tmp_missing);
$period_nums = null;
$tmp_missing = null;
}
$t = '';
foreach($missing as $v) {
$t .= $v.' ';
}
var_dump($t);die();
}
DBConnect();
$db_header = DBBlockNum();
$missing = BlockMissing($db_header);
DBClose();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment