优化静态发布页面的速度

hotfix/paypal-note
尹诚诚 4 years ago
parent 1eb41f2dbf
commit c83bd0cace

@ -410,8 +410,12 @@ class Information extends CI_Controller
} else if (strcasecmp($site_code, "ch") == 0 && !empty($auto_update_cache)) { } else if (strcasecmp($site_code, "ch") == 0 && !empty($auto_update_cache)) {
//读取模板生成PC和移动优先文件 //读取模板生成PC和移动优先文件
$information_new = $this->Information_model->Detail($this->input->post('is_id')); $information_new = $this->Information_model->Detail($this->input->post('is_id'));
$this->make_www_cache('mobile', $information_new); $recommand_information = $this->recommand_information($information);
$this->make_www_cache('pc', $information_new); //$this->benchmark->mark('111');
$this->make_www_cache('mobile', $information_new, $recommand_information);
//$this->benchmark->mark('222');
$this->make_www_cache('pc', $information_new, $recommand_information);
//echo $this->benchmark->elapsed_time('111', '222');
} else if (strcasecmp($site_code, "ah") == 0 && !empty($auto_update_cache)) { } else if (strcasecmp($site_code, "ah") == 0 && !empty($auto_update_cache)) {
//读取模板生成PC和移动优先文件 //读取模板生成PC和移动优先文件
$information_new = $this->Information_model->Detail($this->input->post('is_id')); $information_new = $this->Information_model->Detail($this->input->post('is_id'));
@ -565,7 +569,7 @@ class Information extends CI_Controller
} }
//生成静态文件 $device='mobile' or 'pc' //生成静态文件 $device='mobile' or 'pc'
function make_www_cache($device, $information) function make_www_cache($device, $information, $recommand_information)
{ {
$data = array(); $data = array();
switch ($device) { switch ($device) {
@ -591,7 +595,6 @@ class Information extends CI_Controller
break; break;
default: default:
} }
$breadcrumb_data = $this->Information_model->get_path_exclude_self($information->is_id, $information->is_path); $breadcrumb_data = $this->Information_model->get_path_exclude_self($information->is_id, $information->is_path);
$breadcrumb_structured_data_content = $this->load->view( $breadcrumb_structured_data_content = $this->load->view(
@ -603,7 +606,6 @@ class Information extends CI_Controller
$breadcrumb_structured_data_content, $breadcrumb_structured_data_content,
$template); $template);
//替换模板中的标签 //替换模板中的标签
$template = str_replace('<!--@TITLE@-->', $information->ic_seo_title, $template); $template = str_replace('<!--@TITLE@-->', $information->ic_seo_title, $template);
$template = str_replace('<!--@DESCRIPTION@-->', $information->ic_seo_description, $template); $template = str_replace('<!--@DESCRIPTION@-->', $information->ic_seo_description, $template);
@ -630,6 +632,7 @@ class Information extends CI_Controller
} }
} }
//火车票搜索框添加 -- zp //火车票搜索框添加 -- zp
if ($information->is_parent_id == "278008234") { if ($information->is_parent_id == "278008234") {
//本地测试的火车父类ID为278035939 。网前为278008234 //本地测试的火车父类ID为278035939 。网前为278008234
@ -637,7 +640,6 @@ class Information extends CI_Controller
$template = str_replace('<!--@TRAIN-SEARCH@-->', $template_TrainSearch, $template); $template = str_replace('<!--@TRAIN-SEARCH@-->', $template_TrainSearch, $template);
} }
//非产品页面 //非产品页面
$meta_product_code = get_meta($information->ic_id, 'meta_product_code'); $meta_product_code = get_meta($information->ic_id, 'meta_product_code');
if (empty($meta_product_code)) { if (empty($meta_product_code)) {
@ -672,8 +674,6 @@ class Information extends CI_Controller
$information->ic_content = str_replace('<!--@BREADCRUMB-BLOCK@-->', $breadcrumb_content, $information->ic_content); $information->ic_content = str_replace('<!--@BREADCRUMB-BLOCK@-->', $breadcrumb_content, $information->ic_content);
} }
//---day tours--- 20210922 zp //---day tours--- 20210922 zp
//本地 278035929 //本地 278035929
//网前 278008224 //网前 278008224
@ -741,8 +741,7 @@ class Information extends CI_Controller
$PAG_Scheme = $dataTrippest['PagDetail']->PAG_Scheme; $PAG_Scheme = $dataTrippest['PagDetail']->PAG_Scheme;
$dataTrippest['PAG_Scheme'] = $PAG_Scheme; $dataTrippest['PAG_Scheme'] = $PAG_Scheme;
//接送 //接送
if ($dataTrippest["t_Type"]=="transfer" || 1==1) if ($dataTrippest["t_Type"] == "transfer" || 1 == 1) {
{
$PagList = $this->trippest_model->GetTransfer($dataTrippest['PagDetail']->PAG_SN); $PagList = $this->trippest_model->GetTransfer($dataTrippest['PagDetail']->PAG_SN);
$dataTrippest["PagList"] = $PagList; $dataTrippest["PagList"] = $PagList;
} }
@ -774,9 +773,8 @@ class Information extends CI_Controller
//---day tours end ---- //---day tours end ----
//信息推荐 //信息推荐
$template_recommand = $this->recommand_information($information); $template_recommand = $recommand_information; //$this->recommand_information($information); 从外面传进来pc和移动只需要查一次减少数据库负担
$template = str_replace('<!--@ARTICLENEXT@-->', $this->load->view($template_path . '-next', array('recommands' => $template_recommand), TRUE), $template); $template = str_replace('<!--@ARTICLENEXT@-->', $this->load->view($template_path . '-next', array('recommands' => $template_recommand), TRUE), $template);
// //广告改叫tips防止被插件屏蔽 // //广告改叫tips防止被插件屏蔽
if (!empty($template_recommand['Tips Right TOP'])) { if (!empty($template_recommand['Tips Right TOP'])) {
@ -796,7 +794,6 @@ class Information extends CI_Controller
$information->ic_content = str_replace('<!--@Content-Recommends-Tour@-->', $this->load->view($template_path . '-recommends-tour', array('recommands' => $template_recommand), TRUE), $information->ic_content); $information->ic_content = str_replace('<!--@Content-Recommends-Tour@-->', $this->load->view($template_path . '-recommends-tour', array('recommands' => $template_recommand), TRUE), $information->ic_content);
} }
//顶部全屏大图 //顶部全屏大图
if ($device == 'mobile') { //移动端读取移动大图 if ($device == 'mobile') { //移动端读取移动大图
$meta_addon_picture = get_meta($information->ic_id, 'meta_addon_picture_mobile'); $meta_addon_picture = get_meta($information->ic_id, 'meta_addon_picture_mobile');
@ -825,15 +822,21 @@ class Information extends CI_Controller
if (!empty($meta_news_video) && !empty($meta_video_picture)) { if (!empty($meta_news_video) && !empty($meta_video_picture)) {
$template = str_replace('<!--@TOP-VIDEO@-->', '<div class="detailtopbanner"><video autoplay="" controls="controls" id="bgvid" poster="' . $meta_video_picture . '" src="' . $meta_news_video . '" style="position: inherit;"> </video></div>', $template); $template = str_replace('<!--@TOP-VIDEO@-->', '<div class="detailtopbanner"><video autoplay="" controls="controls" id="bgvid" poster="' . $meta_video_picture . '" src="' . $meta_news_video . '" style="position: inherit;"> </video></div>', $template);
} }
//主样式表,内联模式
if (is_file('D:/wwwroot/origin-data.chinahighlights.com/css/mobile-first.css')) {//主样式表,内联模式,优先读取本地,没有在从网络读取,为了加速
$main_css_string = compress_css(file_get_contents('D:/wwwroot/origin-data.chinahighlights.com/css/mobile-first.css'));
} else {
$main_css_string = compress_css(GET_HTTP('https://proxy-data.chinahighlights.com/css/mobile-first.css')); $main_css_string = compress_css(GET_HTTP('https://proxy-data.chinahighlights.com/css/mobile-first.css'));
}
$template = str_replace('<!--@MAIN-CSS@-->', '<style type="text/css">' . $main_css_string . '</style>', $template); $template = str_replace('<!--@MAIN-CSS@-->', '<style type="text/css">' . $main_css_string . '</style>', $template);
//额外样式 //额外样式
$meta_addon_css = get_meta($information->ic_id, 'meta_addon_css'); $meta_addon_css = get_meta($information->ic_id, 'meta_addon_css');
if (!empty($meta_addon_css)) { if (!empty($meta_addon_css)) {
//引用方式 $template = str_replace('<!--@ADDON-CSS@-->', '<link href="' . $meta_addon_css . '" rel="stylesheet">', $template); if ($meta_addon_css == 'https://proxy-data.chinahighlights.com/css/tour-detail-former.css' && is_file('D:/wwwroot/origin-data.chinahighlights.com/css/tour-detail-former.css')) {
//内联方式 $meta_addon_css_string = compress_css(file_get_contents('D:/wwwroot/origin-data.chinahighlights.com/css/tour-detail-former.css'));
} else {
$meta_addon_css_string = compress_css(GET_HTTP($meta_addon_css)); $meta_addon_css_string = compress_css(GET_HTTP($meta_addon_css));
}
$template = str_replace('<!--@ADDON-CSS@-->', '<style type="text/css">' . $meta_addon_css_string . '</style>', $template); $template = str_replace('<!--@ADDON-CSS@-->', '<style type="text/css">' . $meta_addon_css_string . '</style>', $template);
} }
//额外js //额外js
@ -864,8 +867,13 @@ class Information extends CI_Controller
$template = str_replace('<!--@OG:IMAGE@-->', '<meta property="og:image" content="' . $full_ic_photo . '"><meta property="og:image:secure_url" content="' . $full_ic_photo . '"><meta property="og:image:width" content="800"><meta property="og:image:height" content="450">', $template); $template = str_replace('<!--@OG:IMAGE@-->', '<meta property="og:image" content="' . $full_ic_photo . '"><meta property="og:image:secure_url" content="' . $full_ic_photo . '"><meta property="og:image:width" content="800"><meta property="og:image:height" content="450">', $template);
} }
//设置图片尺寸 //设置图片尺寸
if (is_dir('D:/wwwroot/origin-images.chinahighlights.com') && is_dir('D:/wwwroot/origin-www.chinahighlights.com')) {
$template = $this->html_optimize_lib->set_image_size_local($template, 'D:/wwwroot/origin-www.chinahighlights.com', 'D:/wwwroot/origin-images.chinahighlights.com');
} else {
$template = $this->html_optimize_lib->set_image_size($template); $template = $this->html_optimize_lib->set_image_size($template);
}
// /travelguide/chinese-zodiac/monthly-fortune-for-dog.htm // /travelguide/chinese-zodiac/monthly-fortune-for-dog.htm
$this->benchmark->mark('10');
$html_path = $this->config->item('cache')[$this->config->item('site_code')]['cache_path'] . $information->ic_url; $html_path = $this->config->item('cache')[$this->config->item('site_code')]['cache_path'] . $information->ic_url;
$html_path = str_replace("\\", "/", $html_path); $html_path = str_replace("\\", "/", $html_path);
if (substr($html_path, -1, 1) == '/') { if (substr($html_path, -1, 1) == '/') {
@ -877,7 +885,8 @@ class Information extends CI_Controller
} }
function make_www_cache_gh($information){ function make_www_cache_gh($information)
{
return false; return false;
$data = array(); $data = array();
$data['information'] = $information; $data['information'] = $information;
@ -1100,7 +1109,6 @@ class Information extends CI_Controller
// },$ic_content); // },$ic_content);
//图片加延迟 //图片加延迟
$ic_content = $this->html_optimize_lib->set_lazy_loader($ic_content, 'https://data.chinatravel.com/images/mobile-first/grey.gif'); $ic_content = $this->html_optimize_lib->set_lazy_loader($ic_content, 'https://data.chinatravel.com/images/mobile-first/grey.gif');

@ -99,8 +99,41 @@ class html_optimize_lib
} }
return $html_object->save(); return $html_object->save();
} }
//获取图片尺寸的本地版本,图片存在相同服务器上,速度比较快
//$dataPath data文件夹本地路径
//$imagesPath images文件夹本地路径
public function set_image_size_local($html, $dataPath, $imagesPath)
{
$html_object = str_get_html($html);
foreach ($html_object->find('img') as $image) {
$img_src = $image->src;
if (!empty($image->originalsrc)) {
$img_src = $image->originalsrc;
}
//图片已经设置了尺寸的不再修改
if (empty($image->width) && (strpos($img_src, '//data.') !== false || strpos($img_src, '//images.') !== false)) {//以data或者images开头的域名才能获取尺寸
$img_src_urls = parse_url(trim($img_src));
$request_size[$img_src_urls['host']][] = $img_src_urls['path'];
$file_path = '';
if (strpos($img_src, '//data.') !== false) {
$file_path = $dataPath . $img_src_urls['path'];
}
if (strpos($img_src, '//images.') !== false) {
$file_path = $imagesPath . $img_src_urls['path'];
}
if (is_file($file_path)) {
$properties = getimagesize($file_path);//获取图片属性
if (!empty($properties[0]) && !empty($properties[1])) {
$image->width = $properties[0];
$image->height = $properties[1];
}
}
}
}
return $html_object->save();
}
} }

Loading…
Cancel
Save