Skip to content

Commit

Permalink
feat: optimization write to file
Browse files Browse the repository at this point in the history
  • Loading branch information
Licoy committed May 13, 2022
1 parent 46453af commit dbdfcf5
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions fetch_hosts.php
Expand Up @@ -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) {
Expand All @@ -60,8 +52,8 @@ function hosts_write($filename, $content)

$template = file_get_contents('index-template.php');
file_put_contents('index.php', str_replace('<!--time-->', $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)";

Expand Down

0 comments on commit dbdfcf5

Please sign in to comment.