Browse Source

update semaphore ID

sqlite
ghost 1 year ago
parent
commit
e30466980b
  1. 56
      crawler.php

56
crawler.php

@ -1,36 +1,40 @@ @@ -1,36 +1,40 @@
<?php
$semaphore = sem_get(1);
$semaphore = sem_get(crc32('kvazar-network.crawler_full_node'), 1);
if (false !== sem_acquire($semaphore, 1)) {
if (false === sem_acquire($semaphore, true)) {
require_once(__DIR__ . '/config.php');
require_once(__DIR__ . '/library/sqlite.php');
require_once(__DIR__ . '/library/kevacoin.php');
require_once(__DIR__ . '/library/hash.php');
require_once(__DIR__ . '/library/base58.php');
require_once(__DIR__ . '/library/base58check.php');
require_once(__DIR__ . '/library/crypto.php');
require_once(__DIR__ . '/library/helper.php');
echo "database locked by the another process...\n";
exit;
}
require_once(__DIR__ . '/config.php');
require_once(__DIR__ . '/library/sqlite.php');
require_once(__DIR__ . '/library/kevacoin.php');
require_once(__DIR__ . '/library/hash.php');
require_once(__DIR__ . '/library/base58.php');
require_once(__DIR__ . '/library/base58check.php');
require_once(__DIR__ . '/library/crypto.php');
require_once(__DIR__ . '/library/helper.php');
$db = new SQLite(DB_NAME, DB_USERNAME, DB_PASSWORD);
$kevaCoin = new KevaCoin(KEVA_PROTOCOL, KEVA_HOST, KEVA_PORT, KEVA_USERNAME, KEVA_PASSWORD);
$db = new SQLite(DB_NAME, DB_USERNAME, DB_PASSWORD);
$kevaCoin = new KevaCoin(KEVA_PROTOCOL, KEVA_HOST, KEVA_PORT, KEVA_USERNAME, KEVA_PASSWORD);
$blockLast = $db->getLastBlock();
$blockTotal = $kevaCoin->getblockcount();
$blockLast = $db->getLastBlock();
$blockTotal = $kevaCoin->getblockcount();
if (false === $blockTotal) {
if (false === $blockTotal) {
echo "API connection error.\n";
exit;
}
}
$response = [];
$response = [];
if (CRAWLER_DEBUG) {
if (CRAWLER_DEBUG) {
echo "scanning blockhain...\n";
}
}
for ($blockCurrent = ($blockLast + 1); $blockCurrent <= $blockLast + STEP_BLOCK_LIMIT; $blockCurrent++) {
for ($blockCurrent = ($blockLast + 1); $blockCurrent <= $blockLast + STEP_BLOCK_LIMIT; $blockCurrent++) {
if ($blockCurrent > $blockTotal) {
@ -173,17 +177,11 @@ if (false !== sem_acquire($semaphore, 1)) { @@ -173,17 +177,11 @@ if (false !== sem_acquire($semaphore, 1)) {
}
}
}
}
}
// Debug
if (CRAWLER_DEBUG) {
// Debug
if (CRAWLER_DEBUG) {
echo "scanning completed.\n";
# print_r($response);
}
sem_release($semaphore);
} else {
echo "database locked by the another process...\n";
}

Loading…
Cancel
Save