企业级电子商务与供应链解决方案供应商.
联系我们

+86-13006619568

info@cnopencart.com

深圳,苏州,成都,上海,杭州

扫二维码加微信
wechat

深圳,苏州

+86-16606168892

Top

Opencart加速及服务器安装WDCP之内存数据库优化(重要)

Opencart加速及服务器安装WDCP之内存数据库优化(重要)

前期:

购买VPS,需要购买DDOS服务,安装系统CentOS 6.x 或者 CentOS 7.x  64位

VPS硬盘划分系统盘和文件盘

VPS进行一些安全设置

安装WDCP RPM包更新php版本和数据库版本

1,内存优化修改

自己用网站优化:2G内存

<IfModule mpm_prefork_module>
ServerLimit         512
StartServers          5
MinSpareServers       3
MaxSpareServers      30
MaxClients          512
MaxRequestsPerChild   200
</IfModule>

当我们在服务器上安装完WDCP面板之后,首先我们看一下到底是什么导致占用内存过大,登陆服务器终端,通过以下命令查看各进程所占用的内存比例。

ps -aux

 

根据上图我们发现大部分占用内存的程序是httpd所导致的,针对这个现象我们来优化apache配置文件httpd.conf

优化方法:

通过wdcp后台找到需要修改的文件,文件路径/www/wdlinux/httpd-2.2.22/conf/httpd-wdl.conf

httpd-wdl.conf中找到,这里就是apache在prefork模式下的参数段。将该段各值修改为以下数值:

各字段含义:

ServerLimit         最大客户数
StartServers        服务器启动时建立的子进程数量
MinSpareServers     最小空闲子进程数
MaxSpareServers     最大空闲子进程数
MaxClients          同一时间客户端最大接入请求的数量
MaxRequestsPerChild 每个子进程在其生存期内允许伺服的最大请求数量

注意事项:我们通过下图来正确辨别内存的使用率,只需要看实际的使用内存即可。

小内存(256)

<IfModule mpm_prefork_module>
ServerLimit 128
StartServers 2
MinSpareServers 2
MaxSpareServers 5
MaxClients 128
MaxRequestsPerChild 50
</IfModule>

512MB的vps,apache(perfork模式)最佳的优化配置为:

Timeout 30
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 2
<IfModule prefork.c>
ServerLimit 256
StartServers 4
MinSpareServers 4
MaxSpareServers 10
MaxClients 256
MaxRequestsPerChild 40
</IfModule>

1G内存的VPS上常用的配置

<IfModule mpm_prefork_module>
ServerLimit                    512
StartServers                  5
MinSpareServers            5
MaxSpareServers           20
MaxClients                      512
RequestsPerChild           100
</IfModule>

4G内存的VPS上常用的配置

<IfModule mpm_prefork_module>
ServerLimit         1024
StartServers          5
MinSpareServers       5
MaxSpareServers      30
MaxClients          1024
MaxRequestsPerChild   200
</IfModule>

二、数据库优化配置

自己用2G内存

# mysql conf /etc/my.cnf
# Created by http://www.wdlinux.cn
# Last Updated 2010.06.01

[client]
port        = 3306
socket        = /tmp/mysql.sock
[mysqld]
port        = 3306
socket        = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 4M
table_open_cache = 1024
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
thread_concurrency = 8
max_connections = 512
wait_timeout = 30
interactive_timeout = 30
max_connect_errors = 9
long_query_time = 1
tmp_table_size = 16M
#log-bin=mysql-bin
#binlog_format=mixed
#server-id    = 1
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout

/www/wdlinux/etc/my.cnf

自己网站4G内存配置

# mysql conf /etc/my.cnf
# Created by http://www.wdlinux.cn
# Last Updated 2010.06.01

[client]
port        = 3306
socket        = /tmp/mysql.sock
[mysqld]
port        = 3306
socket        = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 16M
table_open_cache = 1024
sort_buffer_size = 6M
read_buffer_size = 4M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 128
query_cache_size= 128M
thread_concurrency = 8
max_connections = 1024
wait_timeout = 30
interactive_timeout = 30
max_connect_errors = 9
long_query_time = 1
tmp_table_size = 128M
#log-bin=mysql-bin
#binlog_format=mixed
#server-id    = 1
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout

4G内存

[mysqld]
port = 3306
serverid = 1
socket = /tmp/mysql.sock
skip-locking
#避免MySQL的外部锁定,减少出错几率增强稳定性。
skip-name-resolve
#禁止MySQL对外部连接进行DNS解析,使用这一选项可以消除MySQL进行DNS解析的时间。但需要注意,如果开启该选项,则所有远程主机连接授权都要使用IP地址方式,否则MySQL将无法正常处理连接请求!
back_log = 384
#back_log参数的值指出在MySQL暂时停止响应新请求之前的短时间内多少个请求可以被存在堆栈中。 如果系统在一个短时间内有很多连接,则需要增大该参数的值,该参数值指定到来的TCP/IP连接的侦听队列的大小。不同的操作系统在这个队列大小上有它自己的限制。 试图设定back_log高于你的操作系统的限制将是无效的。默认值为50。对于Linux系统推荐设置为小于512的整数。
key_buffer_size = 256M
#key_buffer_size指定用于索引的缓冲区大小,增加它可得到更好的索引处理性能。对于内存在4GB左右的服务器该参数可设置为256M或384M。注意:该参数值设置的过大反而会是服务器整体效率降低!
max_allowed_packet = 4M
thread_stack = 256K
table_cache = 128K
sort_buffer_size = 6M
#查询排序时所能使用的缓冲区大小。注意:该参数对应的分配内存是每连接独占,如果有100个连接,那么实际分配的总共排序缓冲区大小为100 × 6 = 600MB。所以,对于内存在4GB左右的服务器推荐设置为6-8M。
read_buffer_size = 4M
#读查询操作所能使用的缓冲区大小。和sort_buffer_size一样,该参数对应的分配内存也是每连接独享。
join_buffer_size = 8M
#联合查询操作所能使用的缓冲区大小,和sort_buffer_size一样,该参数对应的分配内存也是每连接独享。
myisam_sort_buffer_size = 64M
table_cache = 512
thread_cache_size = 64
query_cache_size = 64M
#指定MySQL查询缓冲区的大小。可以通过在MySQL控制台观察,如果Qcache_lowmem_prunes的值非常大,则表明经常出现缓冲不够的情况;如果Qcache_hits的值非常大,则表明查询缓冲使用非常频繁,如果该值较小反而会影响效率,那么可以考虑不用查询缓冲;Qcache_free_blocks,如果该值非常大,则表明缓冲区中碎片很多。
tmp_table_size = 256M
max_connections = 768
#指定MySQL允许的最大连接进程数。如果在访问论坛时经常出现Too Many Connections的错误提 示,则需要增大该参数值。
max_connect_errors = 10000000
wait_timeout = 10
#指定一个请求的最大连接时间,对于4GB左右内存的服务器可以设置为5-10。
thread_concurrency = 8
#该参数取值为服务器逻辑CPU数量*2,在本例中,服务器有2颗物理CPU,而每颗物理CPU又支持H.T超线程,所以实际取值为4*2=8
skip-networking
#开启该选项可以彻底关闭MySQL的TCP/IP连接方式,如果WEB服务器是以远程连接的方式访问MySQL数据库服务器则不要开启该选项!否则将无法正常连接!
table_cache=1024
#物理内存越大,设置就越大.默认为2402,调到512-1024最佳
innodb_additional_mem_pool_size=4M
#默认为2M
innodb_flush_log_at_trx_commit=1
#设置为0就是等到innodb_log_buffer_size列队满后再统一储存,默认为1
innodb_log_buffer_size=2M
#默认为1M
innodb_thread_concurrency=8
#你的服务器CPU有几个就设置为几,建议用默认一般为8
key_buffer_size=256M
#默认为218,调到128最佳
tmp_table_size=64M
#默认为16M,调到64-256最挂
read_buffer_size=4M
#默认为64K
read_rnd_buffer_size=16M
#默认为256K
sort_buffer_size=32M
#默认为256K
thread_cache_size=120
#默认为60
query_cache_size=32M

※值得注意的是: 

很多情况需要具体情况具体分析

一、如果Key_reads太大,则应该把my.cnf中Key_buffer_size变大,保持Key_reads/Key_read_requests至少1/100以上,越小越好。

二、如果Qcache_lowmem_prunes很大,就要增加Query_cache_size的值。

本人的是独立服务器E5200 2G内存,日IP3W以内。

原来刚弄得时候基本上一天挂好几次。自己也没有用过LINUX原来只是用的WIN 没有仔细配置过,这次换WD很惆怅 很想换成别的,但是对于咱们菜鸟来说,那些代码 更愁人。所以还是坚持,自己一遍遍的设置,终于弄得差不多了。 对于论坛来说 还是别用LAMP了 用LNMP 省很多内存。

我的配置不是说就是对你有用但是 你可以看着修改、。
数据库 配置文件
最大连接数max_connections  5000
连接时间wait_timeout       5
缓冲key_buffer_size         256M
查询缓存query_cache_size    16M
表缓存table_open_cache      512
临时表大小tmp_table_size    6M

key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 512
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
thread_concurrency = 8
max_connections = 5000
wait_timeout = 5
interactive_timeout = 5
max_connect_errors = 100
long_query_time = 1
tmp_table_size = 6M
#log-bin=mysql-bin
#binlog_format=mixed
#server-id = 1
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M

其实这些具体也没有明白到底是啥意思,就是如果256那里小点会出来很多碎片,论坛优化那里 一个小时就好几百MB,所以弄得大了点、

PHP配置
使用内存量 memory_limit    128M
POST最大字节数 post_max_size  8M
允许最大上传文件 upload_max_filesize  2M
程序最长运行时间 max_execution_time   30

查找:output_buffering = Off
修改成:output_buffering = On

disable_functions =passthru,exec,system,chroot,scandir,chgrp,chown,escapeshellcmd,escapeshellarg,shell_exec,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,leak,popepassthru,stream_socket_server,popen

缓存
extension_dir="/www/wdlinux/php/lib/php/extensions/no-debug-zts-20060613"
extension="/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/www/wdlinux/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="600"
eaccelerator.shm_prune_period="600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

缓存那里建议小点,要不WEB的很浪费,我原来设置256WEB用的都上了四百多MB。

上面有不对的希望老鸟们 能够给指点下 有利于更多的兄弟用

还有管理员 大哥 为啥我的站 现在有时候卡的厉害,还得重启下 还有我安装的是LNMAP 可以随意切换的,有时候重启LNMP 不启动还得自己重启下什么原因,  用着是不错 不过配置不会啊,老是有问题,好几万的流量 希望老大能多出点教程,尤其是优化的,用最直观的教程来弄,毕竟小白还是多,技术的少啊。希望老大接受建议。还有希望老鸟们,不要自己光用,把自己的经验发给大家。让我们这些菜鸟 学习下。

mysql 512m-4g内存 配置文件优化记录

>512m-my.ini

[mysqld]
basedir=C:/APMServ5.2.6/MySQL5.1
datadir=C:/APMServ5.2.6/MySQL5.1/data
port=3306
key_buffer=64M
max_allowed_packet=1M
table_cache=256
thread_cache=16
join_buffer_size=4M
sort_buffer=4M
record_buffer=4M
max_connections=500
wait_timeout=120
interactive_timeout=120
max_connect_errors=6000
long_query_time=1
max_heap_table_size=32M
tmp_table_size=16M
thread_concurrency=8
myisam_sort_buffer_size=16M


1g-my.ini

[mysqld]
basedir=C:/APMServ5.2.6/MySQL5.1
datadir=C:/APMServ5.2.6/MySQL5.1/data
port=3306
key_buffer=256M
max_allowed_packet=2M
table_cache=512
thread_cache=32
join_buffer_size=16M
sort_buffer=16M
record_buffer=16M
max_connections=500
wait_timeout=120
interactive_timeout=120
max_connect_errors=30000
long_query_time=1
max_heap_table_size=128M
tmp_table_size=64M
thread_concurrency=8
myisam_sort_buffer_size=64M


2g-my.ini

[mysqld]
basedir=C:/APMServ5.2.6/MySQL5.1
datadir=C:/APMServ5.2.6/MySQL5.1/data
port=3306
key_buffer=384M
max_allowed_packet=4M
table_cache=1024
thread_cache=64
join_buffer_size=32M
sort_buffer=32M
record_buffer=32M
max_connections=500
wait_timeout=120
interactive_timeout=120
max_connect_errors=30000
long_query_time=1
max_heap_table_size=256M
tmp_table_size=128M
thread_concurrency=8
myisam_sort_buffer_size=128M


4g-my.ini

[mysqld]
basedir=C:/APMServ5.2.6/MySQL5.1
datadir=C:/APMServ5.2.6/MySQL5.1/data
port=3306
key_buffer=512M
max_allowed_packet=8M
table_cache=2048
thread_cache=128
join_buffer_size=64M
sort_buffer=64M
record_buffer=64M
max_connections=500
wait_timeout=120
interactive_timeout=120
max_connect_errors=30000
long_query_time=1
max_heap_table_size=256M
tmp_table_size=128M
thread_concurrency=8
myisam_sort_buffer_size=128M

三、php优化参数设置开始自动释放内存

php优化参数设置 点击查看

使用内存量 memory_limit
POST最大字节数 post_max_size
允许最大上传文件 upload_max_filesize
程序最长运行时间 max_execution_time

memory_limit是设置PHP使用内存时空间,一般设置为内存的四分之一,应该就查不多了。如512M内存设置128M,1G内存设置256M。

设置太大会影响系统速度,因为系统和数据库及其他程序同样需要内存空间,一般系统和数据库内存空间是自己分配的。

php.ini中memory_limit设低了会出错,修改了php.ini的memory_limit为128M ,重启nginx,发现好了,原来是PHP的内存不足了。

当激活了 memory_limit,PHP 函数 memory_get_usage() 便可以使用了

四,安装Memcached缓存系统

具体安装如下:
memcache的安装
wget -c http://down.wdlinux.cn/in/memcached_ins.sh
sh memcached_ins.sh
服务启动或停止
service memcached start|stop|restart
或在后台启动也可以

参考:

http://www.wdlinux.cn/bbs/thread-1373-1-1.html

五,安装eAccelerator缓存

eAccelerator(定期检查eaccelerator_cache目录缓存时间是否过期,过期删除)

wget http://down.wdlinux.cn/in/eac0961_ins.sh
sh eac0961_ins.sh

详情:http://www.itbulu.com/wdcp-update-php.html

1、登录到VPS主机客户端,执行以下命令:


wget https://down.wdlinux.cn/in/eac0961_ins.sh
sh eac0961_ins.sh

2、然后在/www/wdlinux/目录下新建一个eaccelerator_cache目录。

3、最后在/www/wdlinux/apache_php-5.2.17/etc中找到php.ini。

4、编辑php.ini,在文件最后加入以下代码:


[eaccelerator]
extension_dir="/www/wdlinux/apache_php-5.2.17/lib/php/extensions/no-debug-zts-20060613/"
extension="eaccelerator.so"
eaccelerator.shm_size="8"
eaccelerator.cache_dir="/www/wdlinux/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

5、重启服务器,刷新探针,这时就能看到eAccelerator安装成功了。

缓存加速的几个方法

http://blog.csdn.net/zqtsx/article/details/40824685

六 Opencart 加速

1. Turn Off Product Counters For Categories

store’s Dashboard navigate to SystemSettings(Your Default Store) EditOption and then scroll down to Products and check No at the Category Product Countradio button. Save and you’re done.

2. Enable GZIP Compression

Compressing files like CSS and JS will contribute to page loading speed so let’s see how this works. From Dashboard navigate to SystemSettings(Your Default Store) EditServer and set the Output Compression Level to some midrange value from 4 to 6. This option is available in values from 0 to 9 and higher numbers are offering more compression, but it also takes more time to compress the files which is not something we are trying to do if we want to speed up OpenCart store.

Opencart加速及服务器安装WDCP之内存数据库优化(重要)-OpenCart - 中文官方网站 | 免费开源商城系统 - OpenCart模板|OpenCart二次开发|OpenCart插件|OpenCart微信|OpenCart APP

Secondly you have to open the .htaccess file and add the following code to it underneath the Rewrite rules:

# compress text, HTML, JavaScript, CSS, and XML
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent

This ends the setup for compressing the external scripts.

3. Enable Browser Caching

This is one more option that includes editing the .htaccess file and telling the browser to keep the downloaded elements in temporary folder for 7 days before requesting everything again from the server. This will considerably increase the page loading speed. Add the following code just underneath the previous code added in step 2.

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType text/css "access plus 1 week"
ExpiresByType application/pdf "access plus 1 week"
ExpiresByType text/x-javascript "access plus 1 week"
ExpiresByType application/x-shockwave-flash "access plus 1 week"
ExpiresByType image/x-icon "access plus 1 week"
ExpiresDefault "access plus 1 week"
</IfModule>
## EXPIRES CACHING ##

4. Enable Keep Alive For Multiple HTTP Requests

This step is for more advanced users familiar with server setup and if you want to avoid seeing the 500 server error message you might want to get in touch with your web host tech support and tell them that KeepAlive needs to be set up in order to speed up your OpenCart store. Also you can skip this step if you don’t want to experiment too much.

If you are running on Apache server login to your server via FTP/SFTP and locate the file:etc/httpd/conf/httpd.conf (for servers like Debian and Ubuntu you have to change theapache2.conf) and open it for editing. Search for Keep and make sure that the values match these:

KeepAlive On
MaxKeepAliveRequests 50
KeepAliveTimeout 7

Next, open the .htaccess file we previously edited and add the following code underneath the other blocks of code from step 3 and then save it:

<ifModule mod_headers.c>
    Header set Connection keep-alive
</ifModule>

NOTE: Remember to check if the server is compatible with this setting because it will result in a 500 server error if it’s not.

5. Load JavaScript Asynchronously

This is a good tip but it has known issue to not load your image slider(s) at once, which you might want to avoid, so try it and decide for yourself. If you don’t like how the page loads revert or skip this step. This step is to ensure that everything gets loaded prior to waiting for the javascript files to be fully loaded. Most of the javascript files are loaded within header.tpl file so you have to navigate to: catalog/view/theme/[YOUR THEME]/common/header.tpl and search for .js (which hopefully will be at the beginning of the file at line 21 or so and should be around five to seven lines of javascript code) and add the command async right after the opening tag <script. Here’s an example:

This is first of seven lines (in my case) of javascript code before adding the async command:

<script type="text/javascript" src="catalog/view/javascript/jquery/jquery-1.7.1.min.js">

And here is what it looks like after:

<script async type="text/javascript" src="catalog/view/javascript/jquery/jquery-1.7.1.min.js">

Once you add the async command to all the javascripts save the file and reupload it viaFTP/SFTP back to the server and overwrite the previous version of the file. Reload your page and see the results how your page is loading/rendering. Mind the loading of the image sliders (main image slider and manufacture logo image slider if you are using one). If you don’t like how the page behaves you can delete the async command and/or skip this tip.

6. Add Image Dimensions To OpenCart

This is a tip about upfront warning the browser about image dimensions on OpenCart store because the built-in image processor does resize them automatically, but it doesn’t include the dimensions in the tags. So navigate to system/library/response.php and open the response.php file in text editor. Find the following line of code:

if ($this->level) {

and just before it add the following code:

//Q: Add width/height tags to all images for Google Page Speed tip:
//http://code.google.com/speed/page-speed/docs/rendering.html#SpecifyImageDimensions
preg_match_all('/<img[^>]+>/i', $this->output, $result);

$img = array();
foreach($result[0] as $img_tag) {
preg_match_all('/(width|height|src)=("[^"]*")/i',$img_tag, $img[$img_tag]);
}

foreach ($img as $k => $info) {
if (count($info) == 3 && $info[1][0] == 'src') {
//if (curl_init(str_replace('"', '', $info[2][0]))) {
$imgfile = str_replace('"', '', $info[2][0]);
$imgfile = str_replace(HTTP_SERVER, DIR_IMAGE . '../', $imgfile);
$imgfile = str_replace(HTTPS_SERVER, DIR_IMAGE . '../', $imgfile);
if (file_exists($imgfile)) {
$image_info = getImageSize(str_replace('"', '', $imgfile));
$k = trim($k, '/>');
$k = trim($k, '>');
$this->output = str_replace($k, ($k . ' ' . $image_info[3]), $this->output);
}
}
}
//

去掉产品列表页产品数量统计

Since OpenCart is the best and most used system for online store creating, we decided to give you a few tips on how to increase the speed of OpenCart.

The speed of your online store depends on the amount of products and categories the system needs to calculate every time the site is loaded. To increase the speed of your online store you need to rewrite some of the files in OpenCart, so that the system does not calculate the products every time. Yes, you have the option to hide the number of categories and products from your site administrative page, but this action will in no way help you increase the speed.

Now that we have cleared this up, let’s get back to the action of optimization of the system.
The optimization can be done in two ways – manually or with a plug-in. While optimization with a plug-in may be easier, it is not the safest choice, because there is a chance of never changing back the information you once changed. That is why we highly recommend you to do the optimization manually. In this way you will know exactly which file you have rewritten and you could rewrite it back at any time.

We will lead you through the manual optimization step by step, but before we do that, we have to warn you that this type of optimization only works on OpenCart 1.5.6.4. It may also work on some older versions of the system.

Now let’s go back to the optimization process. The manual optimization is a simple rewriting of three files in OpenCart. These changes will prevent the system from calculating the categories and products on your site and the speed will increase.

Before starting the processes, you should go to your administration page and from there hide your products, then prepare to rewrite three files:

catalog/controller/product/category.php – The number of categories and products
catalog/controller/common/header.php – The number of products in the menu
catalog/controller/module/category.php – The number of products in menu on the left

In the first file – catalog/controller/product/category.php

Rewrite the code from:

$product_total = $this->model_catalog_product->getTotalProducts($data);

$this->data[‘categories’][] = array(
‘name’ => $result[‘name’] . ($this->config->get(‘config_product_count’) ? ‘ (‘ . $product_total . ‘)’ : ”),
‘href’ => $this->url->link(‘product/category’, ‘path=’ . $this->request->get[‘path’] . ‘_’ . $result[‘category_id’] . $url)
);

To:

//$product_total = $this->model_catalog_product->getTotalProducts($data);
$product_total = 0;
$this->data[‘categories’][] = array(
//’name’ => $result[‘name’] . ($this->config->get(‘config_product_count’) ? ‘ (‘ . $product_total . ‘)’ : ”),
‘name’ => $result[‘name’],
‘href’ => $this->url->link(‘product/category’, ‘path=’ . $this->request->get[‘path’] . ‘_’ . $result[‘category_id’] . $url)
);

catalog/controller/common/header.php

This file is the one containing the function to calculate the amount of products on the site

Find this file and rewrite it from:

$product_total = $this->model_catalog_product->getTotalProducts($data);

$children_data[] = array(
‘name’ => $child[‘name’] . ($this->config->get(‘config_product_count’) ? ‘ (‘ . $product_total . ‘)’ : ”),
‘href’ => $this->url->link(‘product/category’, ‘path=’ . $category[‘category_id’] . ‘_’ . $child[‘category_id’])
);

To:

//$product_total = $this->model_catalog_product->getTotalProducts($data);

$children_data[] = array(
‘name’ => $child[‘name’],
‘href’ => $this->url->link(‘product/category’, ‘path=’ . $category[‘category_id’] . ‘_’ . $child[‘category_id’])
);

catalog/controller/module/category.php

From this file you can stop the calculating of the amount of categories and products on the left menu.

To do this, rewrite this file from:

$product_total = $this->model_catalog_product->getTotalProducts($data);

$total += $product_total;

$children_data[] = array(
‘category_id’ => $child[‘category_id’],
‘name’ => $child[‘name’] . ($this->config->get(‘config_product_count’) ? ‘ (‘ . $product_total . ‘)’ : ”),
‘href’ => $this->url->link(‘product/category’, ‘path=’ . $category[‘category_id’] . ‘_’ . $child[‘category_id’])
);

To:

//$product_total = $this->model_catalog_product->getTotalProducts($data);
//$total += $product_total;
$total = 0;
$product_total = 0;

$children_data[] = array(
‘category_id’ => $child[‘category_id’],
//’name’ => $child[‘name’] . ($this->config->get(‘config_product_count’) ? ‘ (‘ . $product_total . ‘)’ : ”),
‘name’ => $child[‘name’],
‘href’ => $this->url->link(‘product/category’, ‘path=’ . $category[‘category_id’] . ‘_’ . $child[‘category_id’])
);

Most of the online stores that have done these optimizations report wonderful results and a significant loading speed increase.

If you find no difference before and after these changes, you can also use some other methods such as Memcached. Using the cache of Memcached, you can easily speed up your OpenCart. Every time you make a change in your code or add more extensions, make sure you have an up-to-date backup.