Browse Source

stop crawler on network connection lost #11

main
yggverse 8 months ago
parent
commit
d44bf90fe3
  1. 3
      composer.json
  2. 12
      example/config.json
  3. 59
      src/cli/document/crawl.php

3
composer.json

@ -19,6 +19,7 @@
"symfony/dom-crawler": "^6.3", "symfony/dom-crawler": "^6.3",
"jdenticon/jdenticon": "^1.0", "jdenticon/jdenticon": "^1.0",
"yggverse/ftp": "^1.0", "yggverse/ftp": "^1.0",
"gregwar/captcha": "^1.2" "gregwar/captcha": "^1.2",
"yggverse/net": "^1.2"
} }
} }

12
example/config.json

@ -350,5 +350,17 @@
] ]
} }
} }
},
"network":
{
"check":
{
"enabled":true,
"timeout":5,
"socket":
{
"201:5eb5:f061:678e:7565:6338:c02c:5251":80
}
}
} }
} }

59
src/cli/document/crawl.php

@ -65,6 +65,65 @@ if (false === sem_acquire($semaphore, true))
exit; 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 // Init client
try { try {

Loading…
Cancel
Save