<?php header('Content-Type: text/html; charset=utf-8'); ob_start();//Open the cache ?> <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <title>Direct Pure Static</title> </head> <body> <p>Anyone who asks you to recite, the fragrance floats when the water falls</p> </body> </html> <?php //Save the generated static content to the index.html file instead of outputting it to the browser file_put_contents( 'index.html', ob_get_clean()); ?>
Effect picture:
<?php header('Content-Type: text/html; charset=utf-8'); $file_name = 'index2.html'; //If the file exists and the last modification time is less than the set time 10s if(file_exists($file_name) && (time() - filemtime($file_name) < 10)){ //echo time().'<br>';//Current time //echo filemtime( $file_name ).'<br>';//Get the last modification time of the file require_once($file_name);//Introduce files }else{ ob_start(); ?> <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <title>Specify time to trigger generation of pure static </title> </head> <body> <p>onestopweb.iteye.com</p> </body> </html> <?php // output to browser file_put_contents($file_name, ob_get_contents()); } ?>
Effect picture: