magento性能优化策略大全

 

magento的网站实在是太慢了,想了好多办法,参考了好多资料,作了不少测试,总结一下大概的步骤以下php

(继续)css



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的优化。html

 

 

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

(继续)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=512sql

 

这里主要讲的是,本身编译的Apache, 而若是是系统自带的话, Apache所需的模块, 系统会自动加载。数据库

(继续)json

#vi httpd.conf缓存

ServerTokens OSapp

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"

相关文章
相关标签/搜索