正在显示
2 个修改的文件
包含
15 行增加
和
68 行删除
| @@ -5,6 +5,7 @@ | @@ -5,6 +5,7 @@ | ||
| 5 | * Date: 2023/9/14 | 5 | * Date: 2023/9/14 |
| 6 | * Time: 15:42 | 6 | * Time: 15:42 |
| 7 | */ | 7 | */ |
| 8 | + | ||
| 8 | namespace App\Console\Commands; | 9 | namespace App\Console\Commands; |
| 9 | 10 | ||
| 10 | use App\Http\Controllers\Api\NoticeController; | 11 | use App\Http\Controllers\Api\NoticeController; |
| @@ -28,7 +29,8 @@ class DownloadFile extends Command | @@ -28,7 +29,8 @@ class DownloadFile extends Command | ||
| 28 | */ | 29 | */ |
| 29 | protected $description = '处理网站'; | 30 | protected $description = '处理网站'; |
| 30 | 31 | ||
| 31 | - public function handle(){ | 32 | + public function handle() |
| 33 | + { | ||
| 32 | while (true) { | 34 | while (true) { |
| 33 | try { | 35 | try { |
| 34 | $this->websiteHandle(); | 36 | $this->websiteHandle(); |
| @@ -43,23 +45,26 @@ public function handle(){ | @@ -43,23 +45,26 @@ public function handle(){ | ||
| 43 | /** | 45 | /** |
| 44 | * 处理HTML | 46 | * 处理HTML |
| 45 | */ | 47 | */ |
| 46 | - public function websiteHandle(){ | 48 | + public function websiteHandle() |
| 49 | + { | ||
| 47 | $info = Redis::get('handle_html'); | 50 | $info = Redis::get('handle_html'); |
| 48 | - if (!empty($info)){ | 51 | + if (!empty($info)) { |
| 52 | + $this->output('网站更新开始'); | ||
| 49 | $noticeController = new NoticeController(); | 53 | $noticeController = new NoticeController(); |
| 50 | - $infoArr = json_decode($info,true); | ||
| 51 | - if ($infoArr["num"] < 3){ | 54 | + $infoArr = json_decode($info, true); |
| 55 | + if ($infoArr["num"] < 3) { | ||
| 52 | $isSuccess = $noticeController->websiteHtmlHandle($infoArr["url"], $infoArr["domain"]); | 56 | $isSuccess = $noticeController->websiteHtmlHandle($infoArr["url"], $infoArr["domain"]); |
| 53 | - if ($isSuccess){ | 57 | + if ($isSuccess) { |
| 54 | Redis::del('handle_html'); | 58 | Redis::del('handle_html'); |
| 55 | - }else{ | 59 | + } else { |
| 56 | $infoArr["num"]++; | 60 | $infoArr["num"]++; |
| 57 | - Redis::set('handle_html',json_encode($infoArr)); | 61 | + Redis::set('handle_html', json_encode($infoArr)); |
| 58 | } | 62 | } |
| 59 | - }else{ | 63 | + } else { |
| 60 | Redis::del('handle_html'); | 64 | Redis::del('handle_html'); |
| 61 | - Log::info("网站处理失败!",$infoArr); | 65 | + Log::info("网站处理失败!", $infoArr); |
| 62 | } | 66 | } |
| 67 | + $this->output('网站更新结束'); | ||
| 63 | } | 68 | } |
| 64 | return true; | 69 | return true; |
| 65 | } | 70 | } |
app/Console/Commands/demo.php
已删除
100644 → 0
| 1 | -<?php | ||
| 2 | -/** | ||
| 3 | - * Created by PhpStorm. | ||
| 4 | - * User: zhl | ||
| 5 | - * Date: 2023/9/14 | ||
| 6 | - * Time: 15:42 | ||
| 7 | - */ | ||
| 8 | -namespace App\Console\Commands; | ||
| 9 | - | ||
| 10 | -use Illuminate\Console\Command; | ||
| 11 | -use Illuminate\Support\Facades\Storage; | ||
| 12 | -use ZipArchive; | ||
| 13 | - | ||
| 14 | -class Demo extends Command | ||
| 15 | -{ | ||
| 16 | - /** | ||
| 17 | - * The name and signature of the console command. | ||
| 18 | - * | ||
| 19 | - * @var string | ||
| 20 | - */ | ||
| 21 | - protected $signature = 'demo'; | ||
| 22 | - /** | ||
| 23 | - * The console command description. | ||
| 24 | - * | ||
| 25 | - * @var string | ||
| 26 | - */ | ||
| 27 | - protected $description = '测试案例'; | ||
| 28 | - | ||
| 29 | - public function handle(){ | ||
| 30 | - | ||
| 31 | - $filePath = public_path("www.lannx.net.zip"); | ||
| 32 | - if(!file_exists($filePath)){ | ||
| 33 | - $file = fopen($filePath, 'w'); | ||
| 34 | - fclose($file); | ||
| 35 | - } | ||
| 36 | - | ||
| 37 | - $remoteFileUrl = 'https://sitefile.globalso.com/www.lannx.net.zip'; | ||
| 38 | -// $remoteFileUrl = 'https://sitefile.globalso.com/www.fgl-logistics.com.zip'; | ||
| 39 | - $localFilePath = public_path('abc.zip'); | ||
| 40 | - | ||
| 41 | - $remoteFile = fopen($remoteFileUrl, 'rb'); | ||
| 42 | - $localFile = fopen($localFilePath, 'wb'); | ||
| 43 | - | ||
| 44 | - if ($remoteFile && $localFile) { | ||
| 45 | - while (!feof($remoteFile)) { | ||
| 46 | - fwrite($localFile, fread($remoteFile, 1024 * 8), 1024 * 8); | ||
| 47 | - } | ||
| 48 | - fclose($remoteFile); | ||
| 49 | - fclose($localFile); | ||
| 50 | - echo "File downloaded successfully"; | ||
| 51 | - } else { | ||
| 52 | - echo "Failed to download file"; | ||
| 53 | - } | ||
| 54 | - dd('end'); | ||
| 55 | - } | ||
| 56 | - | ||
| 57 | - | ||
| 58 | -} |
-
请 注册 或 登录 后发表评论