Created
January 5, 2018 07:22
-
-
Save yusureabc/34564707391b6275864b94b3cdc0088f to your computer and use it in GitHub Desktop.
首页静态化脚本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 首页静态化脚本 | |
* Author: Yusure | |
* Blog: yusure.cn | |
*/ | |
ini_set( 'date.timezone', 'PRC' ); | |
/* 缓存过期时间 单位:秒 */ | |
$expire = 86400; | |
/* 主动刷新密码 格式:http://test.com/build_index.php?password=123456 */ | |
$password = '123456'; | |
$file_time = @filemtime( 'index.html' ); | |
time() - $file_time > $expire && create_index(); | |
isset( $_GET['password'] ) && $_GET['password'] == $password && create_index(); | |
/** | |
* 生成 index.html | |
*/ | |
function create_index() | |
{ | |
ob_start(); | |
include( 'index.php' ); | |
$content = ob_get_contents(); | |
$content .= "\n<!-- Create time: " . date( 'Y-m-d H:i:s' ) . " -->"; | |
/* 调用更新 */ | |
$content .= "\n<script language=javascript src='build_index.php'></script>"; | |
ob_clean(); | |
$res = file_put_contents( 'index.html', $content ); | |
if ( $res !== false ) | |
{ | |
die( 'Create successful' ); | |
} | |
else | |
{ | |
die( 'Create error' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment