mirror of
https://github.com/kvazar-network/crawler.git
synced 2025-09-11 22:41:52 +00:00
fix state update issue, define global path constants, reorganize state getter
This commit is contained in:
parent
db7ed82516
commit
f6cb2a4191
@ -1,13 +1,16 @@
|
||||
<?php
|
||||
|
||||
// Debug
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('display_startup_errors', '1');
|
||||
error_reporting(E_ALL);
|
||||
|
||||
// Prevent multi-thread execution
|
||||
$semaphore = sem_get(
|
||||
crc32(__FILE__), 1
|
||||
);
|
||||
// Globals
|
||||
define('STATE', __DIR__ . '/../.state');
|
||||
define('CONFIG', __DIR__ . '/../config.json');
|
||||
|
||||
// Load composer dependencies
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
if (false === sem_acquire($semaphore, true))
|
||||
{
|
||||
@ -16,8 +19,13 @@ if (false === sem_acquire($semaphore, true))
|
||||
);
|
||||
}
|
||||
|
||||
// Prevent multi-thread execution
|
||||
$semaphore = sem_get(
|
||||
crc32(__FILE__), 1
|
||||
);
|
||||
|
||||
// Init config
|
||||
if (!file_exists(__DIR__ . '/../config.json'))
|
||||
if (!file_exists(CONFIG))
|
||||
{
|
||||
exit(
|
||||
_('Config not found!')
|
||||
@ -26,30 +34,32 @@ if (!file_exists(__DIR__ . '/../config.json'))
|
||||
|
||||
$config = json_decode(
|
||||
file_get_contents(
|
||||
__DIR__ . '/../config.json'
|
||||
CONFIG
|
||||
)
|
||||
);
|
||||
|
||||
// Init current block state
|
||||
$state = 0;
|
||||
|
||||
if (file_exists(__DIR__ . '/../.state'))
|
||||
function state()
|
||||
{
|
||||
$state = (int) file_get_contents(
|
||||
__DIR__ . '/../.state'
|
||||
);
|
||||
}
|
||||
$state = 0;
|
||||
|
||||
else
|
||||
{
|
||||
file_put_contents(
|
||||
__DIR__ . '/../.state',
|
||||
$state
|
||||
);
|
||||
}
|
||||
if (file_exists(STATE))
|
||||
{
|
||||
$state = (int) file_get_contents(
|
||||
STATE
|
||||
);
|
||||
}
|
||||
|
||||
// Load dependencies
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
else
|
||||
{
|
||||
file_put_contents(
|
||||
STATE,
|
||||
$state
|
||||
);
|
||||
}
|
||||
|
||||
return $state;
|
||||
}
|
||||
|
||||
// Init index
|
||||
switch ($config->index->driver)
|
||||
@ -123,7 +133,7 @@ if (isset($argv[1]))
|
||||
);
|
||||
|
||||
file_put_contents(
|
||||
__DIR__ . '/../.state',
|
||||
STATE,
|
||||
0
|
||||
);
|
||||
|
||||
@ -161,7 +171,7 @@ while (true)
|
||||
if ($blocks = $kevacoin->getBlockCount())
|
||||
{
|
||||
// Begin block index
|
||||
for ($block = $state + 1; $block <= $blocks; $block++)
|
||||
for ($block = state() + 1; $block <= $blocks; $block++)
|
||||
{
|
||||
// Debug progress
|
||||
printf(
|
||||
@ -405,7 +415,7 @@ while (true)
|
||||
|
||||
// Update current block state
|
||||
file_put_contents(
|
||||
__DIR__ . '/../.state',
|
||||
STATE,
|
||||
$block
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user