update semaphore ID

This commit is contained in:
ghost 2023-07-07 11:48:38 +03:00
parent e0831b59f5
commit bfc73fd8bd

View File

@ -1,36 +1,40 @@
<?php <?php
$semaphore = sem_get(1); $semaphore = sem_get(crc32('kvazar-network.crawler_api_node'), 1);
if (false !== sem_acquire($semaphore, 1)) { if (false === sem_acquire($semaphore, true)) {
require_once(__DIR__ . '/config.php'); echo "database locked by the another process..." . PHP_EOL;
require_once(__DIR__ . '/library/sqlite.php'); exit;
require_once(__DIR__ . '/library/api.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); require_once(__DIR__ . '/config.php');
$api = new API(); require_once(__DIR__ . '/library/sqlite.php');
require_once(__DIR__ . '/library/api.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');
$blockLast = $db->getLastBlock(); $db = new SQLite(DB_NAME, DB_USERNAME, DB_PASSWORD);
$blockTotal = $api->getblockcount(); $api = new API();
if (false === $blockTotal) { $blockLast = $db->getLastBlock();
$blockTotal = $api->getblockcount();
if (false === $blockTotal) {
echo "API connection error.\n"; echo "API connection error.\n";
exit; exit;
} }
$response = []; $response = [];
if (CRAWLER_DEBUG) { if (CRAWLER_DEBUG) {
echo "scanning blockhain...\n"; 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) { if ($blockCurrent > $blockTotal) {
@ -173,17 +177,11 @@ if (false !== sem_acquire($semaphore, 1)) {
} }
} }
} }
} }
// Debug // Debug
if (CRAWLER_DEBUG) { if (CRAWLER_DEBUG) {
echo "scanning completed.\n"; echo "scanning completed.\n";
# print_r($response); # print_r($response);
}
sem_release($semaphore);
} else {
echo "database locked by the another process...\n";
} }