stop crawler on network connection lost #11

This commit is contained in:
yggverse 2024-03-24 18:15:26 +02:00
parent b475b4e61b
commit d44bf90fe3
3 changed files with 73 additions and 1 deletions

View file

@ -65,6 +65,65 @@ if (false === sem_acquire($semaphore, true))
exit;
}
// Check network connection
if ($config->network->check->enabled)
{
$network = false;
foreach ($config->network->check->socket as $host => $port)
{
if ($config->cli->document->crawl->debug->level->notice)
{
echo sprintf(
_('[%s] [notice] check network connection to socket "%s" port "%d"...') . PHP_EOL,
date('c'),
$host,
$port
);
}
if (\Yggverse\Net\Socket::isOpen($host, $port, $config->network->check->timeout))
{
if ($config->cli->document->crawl->debug->level->notice)
{
echo sprintf(
_('[%s] [notice] network connection test successful') . PHP_EOL,
date('c')
);
}
$network = true;
break;
}
else
{
if ($config->cli->document->crawl->debug->level->warning)
{
echo sprintf(
_('[%s] [warning] could not connect to socket "%s" port "%d"...') . PHP_EOL,
date('c'),
$host,
$port
);
}
}
}
if (!$network)
{
if ($config->cli->document->crawl->debug->level->error)
{
echo sprintf(
_('[%s] [error] network unreachable!') . PHP_EOL,
date('c')
);
}
exit;
}
}
// Init client
try {