mirror of
https://github.com/kvazar-network/crawler.git
synced 2025-09-12 15:01:57 +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
|
<?php
|
||||||
|
|
||||||
|
// Debug
|
||||||
ini_set('display_errors', '1');
|
ini_set('display_errors', '1');
|
||||||
ini_set('display_startup_errors', '1');
|
ini_set('display_startup_errors', '1');
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
// Prevent multi-thread execution
|
// Globals
|
||||||
$semaphore = sem_get(
|
define('STATE', __DIR__ . '/../.state');
|
||||||
crc32(__FILE__), 1
|
define('CONFIG', __DIR__ . '/../config.json');
|
||||||
);
|
|
||||||
|
// Load composer dependencies
|
||||||
|
require_once __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
if (false === sem_acquire($semaphore, true))
|
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
|
// Init config
|
||||||
if (!file_exists(__DIR__ . '/../config.json'))
|
if (!file_exists(CONFIG))
|
||||||
{
|
{
|
||||||
exit(
|
exit(
|
||||||
_('Config not found!')
|
_('Config not found!')
|
||||||
@ -26,30 +34,32 @@ if (!file_exists(__DIR__ . '/../config.json'))
|
|||||||
|
|
||||||
$config = json_decode(
|
$config = json_decode(
|
||||||
file_get_contents(
|
file_get_contents(
|
||||||
__DIR__ . '/../config.json'
|
CONFIG
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Init current block state
|
// Init current block state
|
||||||
|
function state()
|
||||||
|
{
|
||||||
$state = 0;
|
$state = 0;
|
||||||
|
|
||||||
if (file_exists(__DIR__ . '/../.state'))
|
if (file_exists(STATE))
|
||||||
{
|
{
|
||||||
$state = (int) file_get_contents(
|
$state = (int) file_get_contents(
|
||||||
__DIR__ . '/../.state'
|
STATE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
file_put_contents(
|
file_put_contents(
|
||||||
__DIR__ . '/../.state',
|
STATE,
|
||||||
$state
|
$state
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load dependencies
|
return $state;
|
||||||
require_once __DIR__ . '/../vendor/autoload.php';
|
}
|
||||||
|
|
||||||
// Init index
|
// Init index
|
||||||
switch ($config->index->driver)
|
switch ($config->index->driver)
|
||||||
@ -123,7 +133,7 @@ if (isset($argv[1]))
|
|||||||
);
|
);
|
||||||
|
|
||||||
file_put_contents(
|
file_put_contents(
|
||||||
__DIR__ . '/../.state',
|
STATE,
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -161,7 +171,7 @@ while (true)
|
|||||||
if ($blocks = $kevacoin->getBlockCount())
|
if ($blocks = $kevacoin->getBlockCount())
|
||||||
{
|
{
|
||||||
// Begin block index
|
// Begin block index
|
||||||
for ($block = $state + 1; $block <= $blocks; $block++)
|
for ($block = state() + 1; $block <= $blocks; $block++)
|
||||||
{
|
{
|
||||||
// Debug progress
|
// Debug progress
|
||||||
printf(
|
printf(
|
||||||
@ -405,7 +415,7 @@ while (true)
|
|||||||
|
|
||||||
// Update current block state
|
// Update current block state
|
||||||
file_put_contents(
|
file_put_contents(
|
||||||
__DIR__ . '/../.state',
|
STATE,
|
||||||
$block
|
$block
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user