From dc2e8ab4fb5ae4d29b3ff7fe5a96aa2c1fc35ca7 Mon Sep 17 00:00:00 2001 From: make Date: Wed, 18 Jun 2025 14:34:14 +0800 Subject: [PATCH] debug --- code/app/task/crawler/zw/page/Site.php | 121 ++++++++++++++++++------- 1 file changed, 86 insertions(+), 35 deletions(-) diff --git a/code/app/task/crawler/zw/page/Site.php b/code/app/task/crawler/zw/page/Site.php index 5bd0d73..a132e75 100644 --- a/code/app/task/crawler/zw/page/Site.php +++ b/code/app/task/crawler/zw/page/Site.php @@ -261,57 +261,108 @@ class Site $arrChapterPage = []; $arrPromises = []; - $arrSuccessfulResults = []; - foreach ($arrFilter as $intKey => $arrItem) { $arrPromises[$intKey] = $this->getClient()->getAsync($arrItem['uri']); } $arrResults = Promise\Utils::settle($arrPromises)->wait(); - // $arrSuccessfulResults = array_filter($arrResults, function ($arrResult) { - // return $arrResult['state'] === 'fulfilled'; - // }); foreach ($arrResults as $intKey => $arrResult) { - if ($arrResult['state'] == 'fulfilled') { + if ($arrResult['state'] === 'fulfilled') { + $Response = $arrResult['value']; + $strContent = $Response->getBody()->getContents(); - $arrSuccessfulResults[$intKey] = $arrResult; + // 跳过空内容 + if (empty($strContent)) { + continue; + } - $incKey = config('task.app_name').'_success_getChapterPageList:' . date('Y-m-d'); - $this->redisDailyInc($incKey); - // Cache::store('redis')->inc($incKey); + $ChapterPage = $this->getChapterPage($this, $arrFilter[$intKey]['uri']); + $ChapterPage->setContent($strContent); + $ChapterPage->setData($arrFilter[$intKey]); - } elseif ($arrResult['state'] == 'rejected') { - $incKey = config('task.app_name').'_errer_getChapterPageList:' . date('Y-m-d'); - $this->redisDailyInc($incKey); - // Cache::store('redis')->inc($incKey); - if(config('log.task_debug_log_open_status')){ - // 记录失败原因 - $reason = $arrResult['reason'] instanceof \Exception ? $arrResult['reason']->getMessage() : 'Unknown error'; + $arrChapterPage[] = $ChapterPage; + + // 成功指标 + $this->redisDailyInc(config('task.app_name') . '_success_getChapterPageList:' . date('Y-m-d')); + + } elseif ($arrResult['state'] === 'rejected') { + $this->redisDailyInc(config('task.app_name') . '_errer_getChapterPageList:' . date('Y-m-d')); + + if (config('log.task_debug_log_open_status')) { + $reason = $arrResult['reason'] instanceof \Exception + ? $arrResult['reason']->getMessage() + : 'Unknown error'; $strUri = $arrFilter[$intKey]['uri'] ?? ''; - \think\facade\Log::error("Request failed for getNovelChapterInfo , URI: {$strUri }, Reason: {$reason}"); - var_dump($strUri .' => '.$arrResult['state']); + \think\facade\Log::error("Request failed for getNovelChapterInfo, URI: {$strUri}, Reason: {$reason}"); + var_dump($strUri . ' => ' . $arrResult['state']); } } } - foreach ($arrSuccessfulResults as $intKey => $arrResult) { - $Response = $arrResult['value']; - - $strContent = $Response->getBody()->getContents();; - - $ChapterPage = $this->getChapterPage($this, $arrFilter[$intKey]['uri']); - - $ChapterPage->setContent($strContent); - $ChapterPage->setData($arrFilter[$intKey]); - - $arrChapterPage[] = $ChapterPage; - - $incKey = config('task.app_name').'_success_quit_getChapterPageList:' . date('Y-m-d'); - $this->redisDailyInc($incKey); - } - return $arrChapterPage; + + + // /** @var ChapterPage[] */ + // $arrChapterPage = []; + + // $arrPromises = []; + // $arrSuccessfulResults = []; + + // foreach ($arrFilter as $intKey => $arrItem) { + // $arrPromises[$intKey] = $this->getClient()->getAsync($arrItem['uri']); + // } + + // $arrResults = Promise\Utils::settle($arrPromises)->wait(); + + // // $arrSuccessfulResults = array_filter($arrResults, function ($arrResult) { + // // return $arrResult['state'] === 'fulfilled'; + // // }); + // foreach ($arrResults as $intKey => $arrResult) { + // if ($arrResult['state'] == 'fulfilled') { + + // $arrSuccessfulResults[$intKey] = $arrResult; + + // $incKey = config('task.app_name').'_success_getChapterPageList:' . date('Y-m-d'); + // $this->redisDailyInc($incKey); + // // Cache::store('redis')->inc($incKey); + + // } elseif ($arrResult['state'] == 'rejected') { + // $incKey = config('task.app_name').'_errer_getChapterPageList:' . date('Y-m-d'); + // $this->redisDailyInc($incKey); + // // Cache::store('redis')->inc($incKey); + // if(config('log.task_debug_log_open_status')){ + // // 记录失败原因 + // $reason = $arrResult['reason'] instanceof \Exception ? $arrResult['reason']->getMessage() : 'Unknown error'; + // $strUri = $arrFilter[$intKey]['uri'] ?? ''; + // \think\facade\Log::error("Request failed for getNovelChapterInfo , URI: {$strUri }, Reason: {$reason}"); + // var_dump($strUri .' => '.$arrResult['state']); + // } + // } + // } + + // foreach ($arrSuccessfulResults as $intKey => $arrResult) { + // $Response = $arrResult['value']; + + // $strContent = $Response->getBody()->getContents(); + + // // ✳️ 如果响应内容为空或无效,跳过(你可以根据规则自行扩展) + // if (empty($strContent)) { + // continue; + // } + + // $ChapterPage = $this->getChapterPage($this, $arrFilter[$intKey]['uri']); + + // $ChapterPage->setContent($strContent); + // $ChapterPage->setData($arrFilter[$intKey]); + + // $arrChapterPage[] = $ChapterPage; + + // $incKey = config('task.app_name').'_success_quit_getChapterPageList:' . date('Y-m-d'); + // $this->redisDailyInc($incKey); + // } + + // return $arrChapterPage; }