The previous article explains how to localize resources. This blog post describes how to localize resources and update resources in real time.
On the second-level page, there is no need to update the article page in real time, as long as the page is updated at a scheduled or stable interval. There are several methods:
1. Use cookies or session timing or interval to regenerate pages and files
2. When the size of the generated file exceeds a certain value (for example, 150 MB), delete the file and regenerate it.
Because I use virtual space, I use the second method to save costs.
The following methods can meet the requirements:
Public function content () {// session_start (); $ address = ltrim ($ this-> address, '/'); if (file_exists ($ address )) {// echo $ this-> address; exit;/* $ session_name = "cache_time_html"; if ($ _ COOKIE [$ session_name]) {$ show_data = ''; $ grab_caches_time = Cookie: get ($ session_name); if (time ()-$ grab_caches_time)> $ this-> cache_time_html) {// echo time ()-$ grab_caches_time; exit; $ _ COOKIE [$ session_name] = null; unset ($ _ C OOKIE [$ session_name]); self: creat_html ();} else {// echo time ()-$ grab_caches_time; exit; $ show_data = @ file_get_contents (ltrim ($ this-> address, '/'); print_r ($ show_data); exit ;}} else {Cookie: set ($ session_name, time (); self: creat_html ();} */$ show_data = @ file_get_contents (ltrim ($ this-> address ,'/')); print_r ($ show_data); exit;} else {// echo 2; exit; self: creat_html () ;}/ *** generate static page */private function creat _ Html () {// echo $ this-> html_address; exit; $ content = $ this-> grap-> curl_get_content ($ this-> html_address); if (! $ Content) $ content = @ file_get_contents ($ this-> html_address); if ($ content) {// Replace the deleted content $ param1 = '/<div \ s +? Class = "w"> \ s +? Links :(. *) <\/div>/isU '; $ param2 ='/<form action = "" method = "post" id = "Re_comment" name = "CatRecom"> (. *) <\/form>/isU '; $ param3 ='/<div class = "none"> (. *) <\/div>/isU '; $ param = array ($ param1, $ param2, $ param3); $ this-> grap-> replace_preg ($ content, $ param); $ replace = array ('website navigation', 'site favorites ', '[<a href = "/login.html"> login </a> | <a href = "/register.html"> Registration </a>]'); $ this-> grap-> replace_preg ($ content, $ replace, '1', '0 '); // Save the image to the local machine $ image_place = array (''); $ replace = array ('' => ''); $ this-> grap-> get_image ($ content, $ this-> sorce_url, "/public/images", $ image_place, $ replace ); // Save the css to your local machine $ this-> grap-> get_css ($ content, $ this-> sorce_url, "/public/images"); // print_r ($ content ); exit; // save js locally $ this-> grap-> get_js ($ content, $ this-> sorce_url, "/public/images "); // process the page hyperlink self: href_oprate ($ content); // generate a folder $ this-> grap-> get_file_ad Ress ($ this-> address); $ address = ltrim ($ this-> address, '/');/* $ files = fopen ($ address, 'w '); fwrite ($ file, $ content); fclose ($ file); */@ file_put_contents ($ address, $ content); print_r ($ content); exit ;} else {echo 'does not get the page content. Please refresh and try again! ';}}/*** Process page hyperlink ** @ param srting $ content */private function href_oprate (& $ content) {$ content = str_replace ($ this-> sorce_url, '', $ content); $ zx_patton = array ('',); $ zx_replace = array ('',); $ content = str_replace ($ zx_patton, $ zx_replace, $ content); @ preg_match_all ("/<a ([^>] *)/I", $ content, $ match); $ href = $ match ['1']; foreach ($ href as $ key => $ val) {if (! Stristr ($ val, 'href ') continue; if (stristr ($ val, "http: //") | stristr ($ val, "https ://") | stristr ($ val, "/login.html") | stristr ($ val, "/register.html") | stristr ($ val ,". php ") {$ content = str_replace ($ val,'', $ content);} if (! Stristr ($ val, "javascript") {$ fg = stristr ($ val, 'href = "')? 'Href = "':" href =' "; $ arr_url = explode ($ fg, $ val ); $ arr_url ['1'] = trim ($ arr_url ['1']); if (substr ($ arr_url ['1'], 0, 1) = '"' & substr ($ arr_url ['1'], 0, 1) =" '") continue; if (substr ($ arr_url ['1'], 0, 1) = '/') {if (substr ($ arr_url ['1'], 0, 2 )! = '/"' & Substr ($ arr_url ['1'], 0, 2 )! = "/'") {$ Arr_url ['1'] = substr ($ arr_url ['1'], 0, 1 )! = '/'? '/Html /'. $ arr_url ['1']: '/html '. $ arr_url ['1'] ;}$ new_url = implode ($ arr_url, $ fg); // echo $ val. '| '. $ new_url. '
Demo: http://news.80jiaju.com/