Magento速度优化

一、Magento Compiler可以提高 25% 到 50% 速度

Magento的性能一直是大家比较关心的焦点,现在Magento最新的版本 1.3.2.2 增加了 Magento Compiler 模块,根据官方的资料,该模块可以提高 25% 到 50% 的性能.

我也在测试网站上激活该模块,感觉效果还是不错,目前还是beta版本,不过还是推荐使用Magento的朋友试试。

该模块是从版本 1.3.2.1 开始引入的,如果你的Magento网站已经是1.3.2.1或者更高的版本,该模块已经预装好了,可以直接从后台激活该模块:

System -> Tools -> Compilation (Beta)

然后选 Run Compilation Process, 大约数分钟之后会出现 Compilation Successfully finished 就可以了。如果使用有问题,只需在同一页面下按 Disable 按钮就可以了。

对于使用1.3.2.1之前的版本的朋友,需要升级到最新版本(目前是1.3.2.2)然后再安装该模块,我试过在低于1.3.2.1的Magento网 站中安装,安装后在Tools中找不到Compilation,所以必须升级到1.3.2.1 或更新的版本才能使用该模块,模块URL:

http://www.magentocommerce.com/extension/1359/magento-compiler
可以用下面 Extension Key 通过Magento Connect 来安装:
magento-core/Mage_Compiler

二、让MAGENTO加速一倍的办法

大家可能都发现了,刚装上MAGENTO的时候,MAGENTO是比乌龟还慢的一个系统。。。

如何解决呢?其实很多的主机都已经默认安装一个组件:GZIP。 我们就是要通过修改它来提高MAGENTO的运行速度。

关于能提高多少的问题?大家可以在修改之前去mod_gzip tester 看看你MAGENTO网站的速度,然后在修改之后再去看看。。。

现在我们为MAGENTO开启GZIP。比较方便的方法是修改根目录下.htaccess 文件。我们只需要去掉一些注释就可以了。

在根目录.htaccess找到和以下代码相似的代码,并且把代码修改得和下面一模一样。(去掉前面的#符号。)

.htaccess代码

  • ############################################   
  • ## enable apache served files compression   
  • ## http://developer.yahoo.com/performance/rules.html#gzip    
  • # Insert filter   
  • SetOutputFilter DEFLATE   
  • # Netscape 4 .x has some problems…   
  • BrowserMatch ^Mozilla/4 gzip-only-text/html   
  • # Netscape 4.06 -4.08 have some more problems   
  • BrowserMatch ^Mozilla/4 /.0 [678 ] no-gzip   
  • # MSIE masquerades as Netscape, but it is fine   
  • BrowserMatch /bMSIE !no-gzip !gzip-only-text/html   
  • # Don’t compress images   
  • SetEnvIfNoCase Request_URI /.(?:gif|jpe?g|png)$ no-gzip dont-vary   
  • # Make sure proxies don’t deliver the wrong content   
  • Header append Vary User-Agent env=!dont-vary  


############################################## enable apache served files compression## http://developer.yahoo.com/performance/rules.html#gzip# Insert filterSetOutputFilter DEFLATE# Netscape 4.x has some problems…BrowserMatch ^Mozilla/4 gzip-only-text/html# Netscape 4.06-4.08 have some more problemsBrowserMatch ^Mozilla/4/.0[678] no-gzip# MSIE masquerades as Netscape, but it is fineBrowserMatch /bMSIE !no-gzip !gzip-only-text/html# Don’t compress imagesSetEnvIfNoCase Request_URI /.(?:gif|jpe?g|png)$ no-gzip dont-vary# Make sure proxies don’t deliver the wrong contentHeader append Vary User-Agent env=!dont-vary

另外还有下面这一段:

.htaccess代码

  • ############################################   
  • ## enable resulting html compression   
  • php_flag zlib.output_compression on  


############################################## enable resulting html compressionphp_flag zlib.output_compression on

好了,大功告成,保存你的文件。刷新MAGENTO的缓存,你会觉得速度快了好多好多。

三、end Optimizer
   Zend Optimizer用优化代码的方法来提高PHP4.0应用程序的执行速度。实现的原理是对那些在被最终执行之前由运行编译器(Run- TimeCompiler)产生的代码进行优化。一般情况下,执行使用ZendOptimizer的PHP程序比不使用的要快40%到100%。这意味着 网站的访问者可以更快的浏览网页,从而完成更多的事务,创造更好的客户满意度。更快的反应同时也意味着可以节省硬件投资,并增强网站所提供的服务。所以, 使用ZendOptimizer,就等于提高了电子商务的盈利能力。ZendOptimizer能给PHP用户带来很多益处,特别是那些运营网站的人。快 速运行PHP程序可以显著降低服务器的CPU负载,并可以减少一半的反应时间,也就是从访问者点击链接到服务器开始读取页面之间的时间。

四、站点优化
magento的网站实在是太慢了,想了好多办法,参考了好多资料,做了很多测试,总结一下大概的步骤:
1、压缩js,css代码,如果有必要把所有的css,js分别综合到一个文件中,并压缩,缓存
2、清除magento模板中不必要的注释,为所使用到的图片瘦身
3、优化magento代码,这个步骤工作量大,但可能是效果显著的步骤,不过前提是你非常熟悉magento,彻底删除不用的模块,关闭没用的 block,清除无效,无用的xml(解析xml非常昂贵的),在一个页面中尽量不要大量调用magento的imageresize功能,非常消耗内 存,除非你自己优化代码。
4、mysql配置优化,充分发挥你的硬件资源,下面的数值要根据你的配置调整
My.ini代码

  • key_buffer_size = 512M   
  • max_allowed_packet = 64M   
  • table_cache = 512
  • sort_buffer_size = 4M   
  • net_buffer_length = 8K   
  • read_buffer_size = 4M   
  • read_rnd_buffer_size = 2M   
  • myisam_sort_buffer_size = 64M   
  • tmp_table_size = 128M   
  • query_cache_size = 96M   
  • query_cache_type = 1
  • thread_cache_size = 8
  • max_connections = 400
  • wait_timeout = 300


key_buffer_size = 512Mmax_allowed_packet = 64Mtable_cache = 512sort_buffer_size = 4Mnet_buffer_length = 8Kread_buffer_size = 4Mread_rnd_buffer_size = 2Mmyisam_sort_buffer_size = 64Mtmp_table_size = 128Mquery_cache_size = 96Mquery_cache_type = 1thread_cache_size = 8max_connections = 400wait_timeout = 300
5、将magento的var目录挂载到内存中,加快读取速度,如

mount -t tmpfs -o size=100M,mode=0777 tmpfs var

6、安装php加速器,如APC,XCACHE,eAccelerator,安装方法参考相关的网站

然而归于根本,最大的优化来自于对模板,对代码,对block的优化。

http://www.magentocommerce.com/blog/comments/performance-is-key-notes-on-magentos-performance/

http://www.magentocommerce.com/blog/comments/understanding-magento-scalability-and-performance-1/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值