PDA

View Full Version : مشکل لود بسیار بالای سایت prestashop به دلیل مشکل در شبه کد php



fun_9990
سه شنبه 10 فروردین 1395, 16:26 عصر
مشکل لود بسیار بالای سایت prestashop به دلیل مشکل در شبه کد php دارم

لود سایت رو قبل و بعد از این شبه کد ملاحظه بفرمایید


Load Time 28767 ms - You'd better run your shop on a toaster
Querying Time 713 ms
Queries 180
Memory Peak Usage 72.2 Mb
Included Files 315 files - 4.57 Mb
PrestaShop Cache 0.82 Mb
Global vars 0.91 Mb کد:

PrestaShop Version 1.6.1.0
PHP Version 5.5.32 (OK)
MySQL Version 5.6.29 (OK)
Memory Limit 1024M
Max Execution Time 0s
Smarty Cache enabled
Smarty Compilation never recompile
کد:

config 966 ms 966 ms 11.21 Mb 11.28 Mb
__construct 0 ms 966 ms - Mb 11.28 Mb
init 183 ms 1149 ms 3.82 Mb 15.12 Mb
checkAccess 0 ms 1149 ms - Mb 15.12 Mb
setMedia 21 ms 1170 ms 0.22 Mb 15.33 Mb
postProcess 0 ms 1170 ms - Mb 15.33 Mb
initHeader 0 ms 1170 ms 0.01 Mb 15.33 Mb
initContent 20987 ms 22157 ms 52.96 Mb 68.51 Mb
initFooter 276 ms 22433 ms 0.17 Mb 68.64 Mb
display 6334 ms 28767 ms - Mb 72.18 Mb
کد:

Hook Time Memory Usage
hookHeader 16517 ms 38.50 Mb
=> spthemeconfigurator 16394 ms 38.50 Mb
=> blockcategories 3 ms - Mb
=> blocklayered 0 ms - Mb
=> blockcontactinfos 1 ms - Mb
کد:

Module Time Memory Usage
spthemeconfigurator 16520 ms 41.75 Mb
spmanufactureslider 855 ms 0.75 Mb
=> __construct 70 ms 0.75 Mb
=> hookHeader 12 ms - Mb


ماژول و کد مربوطه

/* ------------------------------------------------------------- */
/* HOOK (displayHeader)
/* ------------------------------------------------------------- */
public function hookHeader($params)
{
$this->_prepHook($params);
global $cookie, $smarty;
$sp_var = array();

$id_shop = $this->context->shop->id;
$is_responsive = Configuration::get('SP_layoutRes');
$showCpanel = Configuration::get('SP_showCpanel');

foreach($this->defaults as $key => $value) {
$sp_var[$key] = Configuration::get($key);
}

// Load Cpanel Config
if($showCpanel){
$this->context->controller->addCSS(_MODULE_DIR_ . $this->name . '/views/css/front/sp-cpanel.css');
//$this->context->controller->addCSS(__PS_BASE_URI__.'modules/'.$this->name.'/views/css/front/jquery.miniColors.css', 'all');
$this->context->controller->addJS(__PS_BASE_URI__.'modules/'.$this->name.'/views/js/front/jquery.miniColors.min.js', 'all');
$this->context->controller->addJS(__PS_BASE_URI__.'modules/'.$this->name.'/views/js/front/sp-cpanel.js', 'all');


if( Tools::getIsset('SP_cplApply') && strtolower( Tools::getValue('SP_cplApply') ) == "apply" ){
foreach($this->defaults as $key => $value) {
if(Tools::getIsset(str_replace('SP_', 'SP_cpl', $key))){
$cookie->__set(str_replace('SP_', 'SP_cpl', $key), Tools::getValue(str_replace('SP_', 'SP_cpl', $key)) );
}
}
Tools::redirect( "index.php" );
}
if( Tools::getIsset('SP_cplReset') && strtolower( Tools::getValue('SP_cplReset') ) == "reset" ){
foreach($this->defaults as $key => $value) {
$cookie->__unset(str_replace('SP_', 'SP_cpl', $key));
}
Tools::redirect( "index.php" );
}

// Set value for params

foreach($this->defaults as $key => $value) {
if($cookie->__get(str_replace('SP_', 'SP_cpl', $key))){
$sp_var[$key] = $cookie->__get( str_replace('SP_', 'SP_cpl', $key));
}

}


}

// compile scss
$scssDir = _PS_ALL_THEMES_DIR_._THEME_NAME_.'/sass/';
$cssDir = _PS_ALL_THEMES_DIR_._THEME_NAME_.'/css/';

/* We are loading css files in this hook, because
* this is the only way to make sure these css files
* will override any other css files.. Otherwise
* module positioning will cause a lot of issues.
*/

/* LOAD CSS */
$language = new Language($cookie->id_lang);
if ($language->is_rtl) $this->context->controller->addCSS(_THEME_CSS_DIR_ . 'bootstrap/bootstrap-rtl.css');
else $this->context->controller->addCSS(_THEME_CSS_DIR_ . 'bootstrap/bootstrap.min.css');


// DO NOT MOVE THIS -> see the file for more information
$this->context->controller->addCSS(_THEME_CSS_DIR_ . 'jquery_plugins/jquery.plugins.css');

// DO NOT MOVE THIS
if($sp_var['SP_themecolorrand']) {
$themeColors = ($this->randColor($sp_var['SP_themecolorrandin'])) ? $this->randColor($sp_var['SP_themecolorrandin']) : $sp_var['SP_themesColors'];
} else {
$themeColors = $sp_var['SP_themesColors'];
}

$smarty->assign( $sp_var );
$themeColors = strtolower($themeColors);
$themeCssName = 'theme-' . str_replace("#", "", $themeColors) . '.css';
$rtlCssName = 'rtl.css';
$resCssName = 'responsive.css';
$ie9CssName = 'ie9.css';

// Load auto-created css files
$cssFile = 'configCss-' . $id_shop . '.css';
if (file_exists(_PS_MODULE_DIR_ . $this->name . '/views/css/front/' . $cssFile)) {
$this->context->controller->addCSS(_MODULE_DIR_ . $this->name . '/views/css/front/' . $cssFile);
}
else {
$this->context->controller->addCSS(_MODULE_DIR_ . $this->name . '/views/css/front/configCSS-default.css');
}

// Load auto-created SCSS Compile
if((!file_exists($cssDir . $themeCssName)) || $sp_var['SP_Scsscompile'] == 1) {
require "scssphp/scss.inc.php";
require "scssphp/compass/compass.inc.php";

$scss = new scssc();
new scss_compass($scss);

if($sp_var['SP_Scssformat']) $cssFormat = $sp_var['SP_Scssformat'];
else $cssFormat = 'scss_formatter_compressed';

$scss->setFormatter($cssFormat);
$scss->addImportPath($scssDir);

$variables = '$color1: '.$themeColors.';';
$string_sass = $variables . file_get_contents($scssDir . "theme.scss");

$rtl_css = $scss->compile('@import "rtl.scss"');
$res_css = $scss->compile('@import "responsive.scss"');
$ie9_css = $scss->compile('@import "ie9.scss"');
$string_css = $scss->compile($string_sass);
$string_css = preg_replace('/\/\*[\s\S]*?\*\//', '', $string_css); // remove mutiple comments

file_put_contents($cssDir . $themeCssName, $string_css);
file_put_contents($cssDir . $rtlCssName, $rtl_css);
file_put_contents($cssDir . $resCssName, $res_css);
file_put_contents($cssDir . $ie9CssName, $ie9_css);
}
$this->context->controller->addCSS(array(
__PS_BASE_URI__.'themes/'._THEME_NAME_.'/css/'.$themeCssName
));


if($is_responsive) $this->context->controller->addCSS(_THEME_CSS_DIR_ . 'responsive.css');
else $this->context->controller->addCSS(_THEME_CSS_DIR_ . 'bootstrap/none-responsive.css');



/* GLOBAL SMARTY VARS */
/* LOAD JS */
// Load custom JS files
$controller_name = Dispatcher::getInstance()->getController();
$this->context->controller->addJqueryPlugin('backtotop', _THEME_JS_DIR_ . 'sp_lib/');
if(Configuration::get('SP_keepMenuTop') == 1) $this->context->controller->addJqueryPlugin('keepmenu', _THEME_JS_DIR_ . 'sp_lib/');
if(Configuration::get('SP_animationScroll') == 1) $this->context->controller->addJqueryPlugin('scrollReveal', _THEME_JS_DIR_ . 'sp_lib/');

// if (Module::isInstalled('blocklayered') && Module::isEnabled('blocklayered') && $controller_name == 'category') {
// $this->context->controller->addJqueryPlugin('ui.touch-punch.min', _THEME_JS_DIR_ . 'sp_lib/');
// }
$this->context->controller->addJqueryPlugin('prettyPhoto', _THEME_JS_DIR_ . 'sp_lib/');
$this->context->controller->addJqueryPlugin('global', _THEME_JS_DIR_ . 'sp_lib/');

}
که قرار دادم بالای 75 درصد لود سایت از همین قسمت ناشی میشه .
بعد از حذف این قسمت از کد میزان لودینگ از حدود 29 ثانیه رسید به 8.4 ثانیه اما خوب قالب به هم ریخته میشه
برای همین مشکل رو دقیقا همین قسمت می بینم
ملاحظه بفرمایید

کد:




Load Time 8475 ms - You'd better run your shop on a toaster
Querying Time 441 ms
Queries 171
Memory Peak Usage 38.8 Mb
Included Files 310 files - 4.43 Mb
PrestaShop Cache 0.78 Mb
Global vars 0.87 Mb