magento模版功能强大,已被大众所熟知,但也有不少朋友反映,magento网站的速度偏慢。在参考了一些资料后,对magento性能提升做一下小结。希望对各位读者有所帮助。

  1. 压缩js,css代码,如果有必要把所有的css,js分别综合到一个文件中,并压缩,缓存
  2. 清除magento模板中不必要的注释,为所使用到的图片瘦身
  3. 优化magento代码,这个步骤工作量大,但可能是效果显著的步骤,不过前提是你非常熟悉magento,彻底删除不用的模块,关闭没用的block, 清除无效,无用的xml(解析xml非常昂贵的),在一个页面中尽量不要大量调用magento的image resize功能,非常消耗内存,除非你自己优化代码。
  4. mysql配置优化,充分发挥你的硬件资源,下面的数值要根据你的配置调整 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
  5. 将magento的var目录挂载到内存中,加快读取速度,如mount -t tmpfs -o size=100M,mode=0777 tmpfs var
  6. 安装php加速器,如APC,XCACHE,eAccelerator,安装方法参考相关的网站。然而归于根本,最大的优化来自于对模板,对代码,对block的优化。

在Magento的优化中, Mysql的优化是很重要的,在Magento的官方网给出了有关Mysql的优化, 官方网并没有要我们把Mysql的存储引擎改为innodb, 但我觉的得这是很有必要的,当改成innodb后,还得把Mysql的配置文件修改修改下, 有时根据官方的文档来并不能成功, 这时就要看你的环境而定了, 下面给出我所配置的mysql文件给大家参考:

    [mysqld]
  • datadir=/var/lib/mysql
  • socket=/var/lib/mysql/mysql.sock
  • user=mysql
  • # Default to using old password format for compatibility with mysql 3.x
  • # clients (those using the mysqlclient10 compatibility package).
  • old_passwords=1
  • default-character-set=utf8
  • #init_connect='SET NAMES utf8'
  • default-storage_engine = innodb
  • # To allow mysqld to connect to a MySQL Cluster management daemon, uncomment
  • # these lines and adjust the connectstring as needed.
  • #ndbcluster
  • #ndb-connectstring="nodeid=4;host=localhost:1186"

[client]

  • #default-character-set=utf8

[mysqld_safe]

  • log-error=/var/log/mysqld.log

[Magento]

  • max_connections = 1000
  • max_connect_error = 10
  • table_cache = 1024
  • max_allowed_packet = 16M
  • max_heap_table_size = 64M
  • sort_buffer_size = 8M
  • join_buffer_size = 8M
  • thread_cache_size = 8
  • thread_concurrency = 8
  • query_cache_size = 64M
  • query_cache_limit = 2M
  • tmp_tables_size = 64M
  • key_buffer_size = 32M
  • read_buffer_size = 2M
  • read_rnd_buffer_size = 16M
  • bulk_insert_buffer_size = 64M
  • myisam_sort_buffer_size = 128M
  • myisam_max_sort_file_size = 10G
  • myisam_max_extra_sort_file_size=10G
  • myisam_repair_threads = 1
  • myisam_recover
  • innodb_additional_mem_pool_size = 16M
  • innodb_log_buffer_size = 8M
  • innodb_log_file_size = 512M
  • innodb_log_files_in_group = 2
  • innodb_buffer_pool_size = 3G
  • innodb_data_file_path = ibdata1:3G;ibdata2:1G:autoextend
  • innodb_autoextend_increment=512

这里主要讲的是自己编译的Apache, 而如果是系统自带的话, Apache所需的模块, 系统会自动加载。

  • #vi httpd.conf
  • ServerTokens OS
  • ServerRoot "/etc/httpd"
  • PidFile run /httpd.pid
  • Timeout 120
  • KeepAlive off
  • MaxkeepAliveRequests 100
  • KeepAliveTimeout 15
  • StartServers 100
  • MinSpareServers 100
  • MaxSpareServers 150
  • ServerLimit 256
  • MaxClient 256
  • MaxRequestsPerChild 40000
  • Listen *:80

在这里还要一些必须的Apache模块

    1. mod_authz_host.so
    2. mod_expires.so
    3. mod_deflate.so
    4. mod_mime.so
    5. mod_dir.so
    6. mod_rewrite.so 这个模块很重要, 当设置Magento地址重写时,要用到
    7. mod_log_config.so
    8. libphp5.so 你有可能用的是php4, 那就得改成libphp4.so

注意:

在安装好Apache后, 我们还能让Apache识别以php为后缀的文件

AddType application/x-httpd-php .php .phtml

好了, 到这就讲完了, 这章其实对Magento的优化不大, 但有些模块又不能少, 少了, Magento后台可能出问题

当我们安装好Magento时, 为了加快Magento的速度,我们一般还要做一些对于Magento服务的优化, 来提高Magento被访问的速度。 一般我们会从三个角度去考虑Magento的优化, 如: 安装Magento的系统; Magento模板中的代码; Magento所用到的数据库。 在这我们主要讲的是Magento系统的优化

Magento是在PHP环境下开发的, 所以优化PHP对Magento有着不小的影响,下面是Magento标准的PHP配置。

对于Magento所需的扩展, 只开启所需的就可以了

# Required extensions

  • extension=bcmath.so
  • extension=curl.so
  • extension=dom.so
  • extension=gd.so
  • extension=mcrypt.so
  • extension=memcache.so
  • extension=mhash.so
  • extension=pdo.so
  • extension=pdo_mysql.so
  • extension=mysql.so
  • extension=xmlwriter.so

下面的一些扩展并不需要开启, 我们可以把它们关闭

# Not  needed extensions from default setup

  • ;;extension=dbase.so
  • ;;extension=json.so
  • >
  • ;;extension=mysqli.so
  • ;;extension=pdo_sqlite.so
  • ;;extension=sqlite.so
  • ;;extension=wddx.so
  • ;;extension=smlreader.so
  • ;;extension=xsl.so
  • ;;extesnion=zip.so

事无绝对, 当你的系统环境需要某个扩展时, 可以按照需要开启

下面所要讲的, 也是PHP中优化的重点, 将会讲到二种方法,二选一就行了, 切忌, 不能同时应用二种方案

一,安装APC扩展, APC, 用来优化PHP本身, 提高PHP的运行速度

# APC configuration apecifics if it is used

extension=apc.so

apc.shm_size=256

apc.num_files_hint=10000

apc.user_entries_hint=10000

apc.max_file_size=5M

二,安装eaccelerator加速器,功能跟APC类似, 在这就不多说了。

安装好eaccelerator后,将会产生eaccelerator模块

zend_extension="/usr/lib64/php/modules/eaccelerator.so"

eaccelerator.shm_size = "256"

360magento提供专业的基于magento系统的电商网站开发服务,如有需求或相关咨询,请与我们联系