作者 刘锟

update

... ... @@ -5,6 +5,7 @@
* Date: 2023/9/14
* Time: 15:42
*/
namespace App\Console\Commands;
use App\Http\Controllers\Api\NoticeController;
... ... @@ -28,7 +29,8 @@ class DownloadFile extends Command
*/
protected $description = '处理网站';
public function handle(){
public function handle()
{
while (true) {
try {
$this->websiteHandle();
... ... @@ -43,23 +45,26 @@ public function handle(){
/**
* 处理HTML
*/
public function websiteHandle(){
public function websiteHandle()
{
$info = Redis::get('handle_html');
if (!empty($info)){
if (!empty($info)) {
$this->output('网站更新开始');
$noticeController = new NoticeController();
$infoArr = json_decode($info,true);
if ($infoArr["num"] < 3){
$infoArr = json_decode($info, true);
if ($infoArr["num"] < 3) {
$isSuccess = $noticeController->websiteHtmlHandle($infoArr["url"], $infoArr["domain"]);
if ($isSuccess){
if ($isSuccess) {
Redis::del('handle_html');
}else{
} else {
$infoArr["num"]++;
Redis::set('handle_html',json_encode($infoArr));
Redis::set('handle_html', json_encode($infoArr));
}
}else{
} else {
Redis::del('handle_html');
Log::info("网站处理失败!",$infoArr);
Log::info("网站处理失败!", $infoArr);
}
$this->output('网站更新结束');
}
return true;
}
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2023/9/14
* Time: 15:42
*/
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
use ZipArchive;
class Demo extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'demo';
/**
* The console command description.
*
* @var string
*/
protected $description = '测试案例';
public function handle(){
$filePath = public_path("www.lannx.net.zip");
if(!file_exists($filePath)){
$file = fopen($filePath, 'w');
fclose($file);
}
$remoteFileUrl = 'https://sitefile.globalso.com/www.lannx.net.zip';
// $remoteFileUrl = 'https://sitefile.globalso.com/www.fgl-logistics.com.zip';
$localFilePath = public_path('abc.zip');
$remoteFile = fopen($remoteFileUrl, 'rb');
$localFile = fopen($localFilePath, 'wb');
if ($remoteFile && $localFile) {
while (!feof($remoteFile)) {
fwrite($localFile, fread($remoteFile, 1024 * 8), 1024 * 8);
}
fclose($remoteFile);
fclose($localFile);
echo "File downloaded successfully";
} else {
echo "Failed to download file";
}
dd('end');
}
}