From bc9fc470e631434918f060ae13be61bb42568a1d Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 7 Apr 2024 04:57:02 +0300 Subject: [PATCH] make custom resolver optionally required to continue the crawl #15 --- example/config.json | 1 + src/cli/document/crawl.php | 54 +++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/example/config.json b/example/config.json index c0ba097..e9f1f23 100644 --- a/example/config.json +++ b/example/config.json @@ -138,6 +138,7 @@ "resolver": { "enabled":true, + "require":false, "providers": [ "1.1.1.1", diff --git a/src/cli/document/crawl.php b/src/cli/document/crawl.php index bce3101..1f022d7 100644 --- a/src/cli/document/crawl.php +++ b/src/cli/document/crawl.php @@ -295,25 +295,49 @@ foreach($index->search('') else { - // Log event - if ($config->cli->document->crawl->debug->level->warning) + // Custom resolver required to continue + if ($config->cli->document->crawl->resolver->require) { - echo sprintf( - _('[%s] [warning] could not resolve "%s" (attempt: %d, response: %s), wait for reconnection...') . PHP_EOL, - date('c'), - $base->getHost(), - $attempt++, - print_r( - $errors, - true - ) + // Log event + if ($config->cli->document->crawl->debug->level->warning) + { + echo sprintf( + _('[%s] [warning] could not resolve "%s" (attempt: %d, response: %s), wait for reconnection...') . PHP_EOL, + date('c'), + $base->getHost(), + $attempt++, + print_r( + $errors, + true + ) + ); + } + + // Next connection delay + sleep( + $config->cli->document->crawl->resolver->connection->delay ); } - // Next connection delay - sleep( - $config->cli->document->crawl->resolver->connection->delay - ); + // Use system-wide resolver, break the pending loop + else + { + if ($config->cli->document->crawl->debug->level->warning) + { + echo sprintf( + _('[%s] [warning] could not resolve "%s" (attempt: %d, response: %s), use system-wide...') . PHP_EOL, + date('c'), + $base->getHost(), + $attempt++, + print_r( + $errors, + true + ) + ); + } + + break; + } } } while (!$resolved);