From dbdfcf5d067c2745fbd0298704ef36b2ef63e6b7 Mon Sep 17 00:00:00 2001 From: Licoy Date: Fri, 13 May 2022 15:18:28 +0800 Subject: [PATCH] feat: optimization write to file --- fetch_hosts.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/fetch_hosts.php b/fetch_hosts.php index 93f4330..56eba61 100644 --- a/fetch_hosts.php +++ b/fetch_hosts.php @@ -40,14 +40,6 @@ "objects.githubusercontent.com" ]; -function hosts_write($filename, $content) -{ - $fs = fopen($filename, 'w+'); - fwrite($fs, $content); - fflush($fs); - fclose($fs); -} - $github_hosts = []; $hosts_content = "# fetch-github-host begin\n"; foreach ($github_urls as $url) { @@ -60,8 +52,8 @@ function hosts_write($filename, $content) $template = file_get_contents('index-template.php'); file_put_contents('index.php', str_replace('', $utc_date, $template)); -hosts_write('hosts.txt', $hosts_content); -hosts_write('hosts.json', json_encode($github_hosts)); +file_put_contents('hosts.txt', $hosts_content); +file_put_contents('hosts.json', json_encode($github_hosts)); echo "fetch success! ($utc_date)";