DownloadFile.php
1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2023/9/14
* Time: 15:42
*/
namespace App\Console\Commands;
use App\Http\Controllers\Api\NoticeController;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
class DownloadFile extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'handle_html';
/**
* The console command description.
*
* @var string
*/
protected $description = '处理网站';
public function handle(){
while (true) {
try {
$this->websiteHandle();
sleep(30);
} catch (\Exception $e) {
sleep(30);
}
}
return true;
}
/**
* 处理HTML
*/
public function websiteHandle(){
$info = Redis::get('handle_html');
if (!empty($info)){
$noticeController = new NoticeController();
$infoArr = json_decode($info,true);
if ($infoArr["num"] < 3){
$isSuccess = $noticeController->websiteHtmlHandle($infoArr["url"], $infoArr["domain"]);
if ($isSuccess){
Redis::del('handle_html');
}else{
$infoArr["num"]++;
Redis::set('handle_html',json_encode($infoArr));
}
}else{
Redis::del('handle_html');
Log::info("网站处理失败!",$infoArr);
}
}
return true;
}
/**
* 输出处理日志
* @param $message
* @return bool
*/
public function output($message)
{
echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
return true;
}
}