mirror of
https://github.com/kvazar-network/crawler-api-node.git
synced 2025-08-27 23:11:47 +00:00
update semaphore ID
This commit is contained in:
parent
e0831b59f5
commit
bfc73fd8bd
56
crawler.php
56
crawler.php
@ -1,36 +1,40 @@
|
||||
<?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');
|
||||
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');
|
||||
echo "database locked by the another process..." . PHP_EOL;
|
||||
exit;
|
||||
}
|
||||
|
||||
$db = new SQLite(DB_NAME, DB_USERNAME, DB_PASSWORD);
|
||||
$api = new API();
|
||||
require_once(__DIR__ . '/config.php');
|
||||
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();
|
||||
$blockTotal = $api->getblockcount();
|
||||
$db = new SQLite(DB_NAME, DB_USERNAME, DB_PASSWORD);
|
||||
$api = new API();
|
||||
|
||||
if (false === $blockTotal) {
|
||||
$blockLast = $db->getLastBlock();
|
||||
$blockTotal = $api->getblockcount();
|
||||
|
||||
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)) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 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…
x
Reference in New Issue
Block a user