Magento optimization Template static

Source: Internet
Author: User

The recent home is very slow, run Magento profile check, found that the first page of a templat run time accounted for half, about 6s.

With Magento's own cache, try to cache the code in collection, but don't know why it has failed, and finally decided to turn the entire template into a static page, regenerated every two hours.

The code is as follows:

<?PHP$dir= Mage::getbasedir (). DS. ' var '.DS;$fileName=$dir.‘ Real_static_categories.phtml ';if(!file_exists($fileName)|| (Filemtime($fileName) && ( Time()-Filemtime($fileName) >7200))){    $text=mage::app ()->getlayout ()->createblock (' Catalog/product_list ')->settemplate (' catalog/product/ Productcarousel/carouselblocks/categories.phtml ')toHtml (); $file=fopen($fileName, ' W '); fwrite($file,$text); fclose($file);}$file=fopen($fileName, ' R ');Echo fread($file,filesize($fileName));fclose($file);?>

The effect is good, and the access speed is increased by one times.

Magento optimization Template static

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.