Ejemplo n.º 1
0
<?php

// (c) Har01d
require_once 'include.php';
$total_blocks = daemon('getblockcount');
$last_known_block = pg_query('select max(height) as max_height from XTTestnetBlocks');
if (pg_num_rows($last_known_block) <= 0) {
    $start_with = FIRST_BLOCK_TO_PROCESS - 1;
} else {
    $start_with = pg_fetch_assoc($last_known_block)['max_height'];
}
if (is_null($start_with)) {
    $start_with = FIRST_BLOCK_TO_PROCESS - 1;
}
for ($i = $start_with + 1; $i <= $total_blocks; $i++) {
    $block_hash = daemon('getblockhash', [$i]);
    $block = daemon('getblock', [$block_hash]);
    $query = "insert into XTTestnetBlocks values ({$block['height']}, {$block['version']}, {$block['size']})";
    pg_query($query);
}
Ejemplo n.º 2
0
/**
 * 地址:日志服务器
 * @var string
 */
define('SERVER_URL', "udp://192.168.0.21:9999");
/**
 * 客户端:发送进程数
 * @var int
 */
define('WORKER_NUM', 5);
/**
 * 死循环睡眠周期
 * @var int
 */
define('SLEEP_MICRO_SECONDS', 20);
daemon();
$queue = msg_get_queue(MSG_KEY, MSG_PRIVILEGE);
if ($queue === false) {
    error_log("[ERROR]create queue fail\n", 3, RUNTIME_LOG_PATH);
    exit;
}
$worker_pid = array();
for ($i = 1; $i < WORKER_NUM; $i++) {
    $pid = pcntl_fork();
    if ($pid > 0) {
        $worker_pid[] = $pid;
        error_log("[RUNTIME]create worker {$i}.pid = {$pid}\n", 3, RUNTIME_LOG_PATH);
        continue;
    } elseif ($pid == 0) {
        proc_worker($i);
        exit;
function main()
{
    global $argv;
    if (count($argv) > 1) {
        switch (strtolower($argv[1])) {
            case "generate":
                $ret = generate();
                break;
            case "index":
                $ret = index();
                break;
            case "search":
                $ret = search();
                break;
            case "daemon":
                $ret = daemon();
                break;
            case "merge":
                $ret = merge();
                break;
            default:
                $ret = false;
        }
        if ($ret) {
            return;
        }
    }
    print_usage();
}