X-Cart:Performance tips

From X-Cart 4 Classic
Revision as of 16:09, 15 March 2011 by Vladimir Gurinenko (talk | contribs) (Edited in the context of BT 85873)
Jump to: navigation, search

There are several options that may help you to speed up site. Try them out first.

Moving images to file system. For v.3.5.x and 4.0.x

For each image you want to display, a separate connection has to be opened to your database. Even if it's only one image per page, doubling the connections to the database isn't fun to think about.

Each time you do <img src="image.php?imageid=345"> or something similar, that's a separate request to the server, with PHP going to receive that image from the database. Even if you do use scripting to grab images from a non-public branch of your file tree, just using file reading creates very, very little overhead, while hitting the database creates a lot. Just connecting to the database alone, without any queries, is something which already takes a significant amount of server time (more in the sense of processing cycles than actual time).

Storing your images in database tables is not recommended from the performance point of view. Our advice is to place images into the file system. It can easily be done by modifying a single setting in the control panel. For details, study X-Cart:Images Location Management page.

After that modify original .htaccess file (in /files directory) and change the code to:

<FilesMatch "\.(gif|jpe?g|png|GIF|JPE?G|PNG|)$">
Allow from all
</FilesMatch>
Deny from all

Toggling off tracking statistics

It is strongly recommended you disable all the modules and functions that you do not need. If you experience problems with X-Cart performance, one of the first things you should do is disable the module Advanced Statistics. This module significantly slows down X-Cart by storing statistical information in the database.

In X-Cart v3.5.x or later:

Advanced Statistics can be disabled via the 'Modules' section of X-Cart's Admin area.

In X-Cart v3.4.x:

in the customer/auth.php file, make the line

include "../include/atracking.php";

as follow:

#include "../include/atracking.php";
Note: As an alternative to "Advanced Statistics" module, you can enable the "Google Analytics" module to use Google Analytics system with your store.

Cleaning statistics tables

For v.3.5.x and 4.0.x.

In the admin back-end of x-cart: ‘Summary’ page - > ‘Statistics clearing’.

For v.4.1.x: Statistics can be cleared via admin area: 'Summary' page, section 'Tools/Statistics clearing'.

Optimizing SQL tables

X-Cart stores its data in database tables, and over time these tables may become fragmented/less organized. This is especially true if you make changes to the data in your store's database tables directly.

In X-Cart v.4.1.x or later:

X-Cart provides a tool that allows you to defragment the database and reclaim the unused space: 'Optimize tables'. For details on using this tool, see X-Cart: Advanced Tools page.

In X-Cart v.3.5.x and 4.0.x:

Execute the following sql query for each x-cart table

OPTIMIZE TABLE <table_name>;

where replace <table_name> with the name of a table. You will find the list of x-cart tables using the next sql query:

SHOW TABLES;

Optimizing CSS

To optimize CSS, you can take advantage of the load_defer and load_defer_code Smarty tags. Both these tags handle the operations of assembling and displaying cached CSS code. For more information on using these tags, please refer to CSS and JavaScript Optimization.

Optimizing JavaScript

To optimize JavaScript, you can also use the load_defer and load_defer_code Smarty tags to enable assembling and displaying cached JavaScript code. For further details on using these tags for JavaScript, please refer to CSS and JavaScript Optimization.

Caching images

When user views the 'Product details' page, X-Cart serves reduced-size copies of the product image until user requests the full-size copy of it. This saves bandwidth and cuts the page load time. Image caching requires GDLib (a GD extension for PHP) installed and properly configured on the server. You can manually generate image cache by clicking Re-generate image cache in the 'Maintenance' section of the admin area. For more information on setting up product images, please refer to Advanced Tools.

Generating HTML catalog

Additionally, it is advisable to create HTML catalog. After generation of HTML catalog, your customer zone is presented as a set of static pages linked together without actual PHP scripts execution and database queries. It may significantly lower loading of your server.

Compressing HTML source

You may try to put the following lines in the php.ini file:

output_handler =
zlib.output_compression = On
zlib.output_compression_level = 1

You can put any figure in the compression level between -1 and 9, just muck around and see what works best for your particular store.

Or if you are using Apache server and .htaccess files are enabled you may try to add

php_flag zlib.output_compression On

to the .htaccess in the store root.

Installing Zend Optimizer

The Zend Optimizer is a free application that runs the files encoded by the Zend Encoder and Zend SafeGuard Suite, while enhancing the running speed of PHP applications. Many scripts require that you have Zend Optimizer installed so you are able to run them on your server while decrypting and running them on-the-fly while increasing runtime performance.

Install additional Apache modules (optional)

The idea behind GZIP-encoding documents is very straightforward. Take a file that is to be transmitted to a Web client, and send a compressed version of the data, rather than the raw file. Depending on the size of the file, the compressed version can run anywhere from 50% to 20% of the original file size.

In Apache, this can be achieved using Content Negotiation, which requires that two separate sets of HTML files be generated: one for clients who can handle GZIP-encoding, and one for those who can't. This solution sends gzip-encoded files to clients who understand them, but does not allow for the compression of dynamically-generated pages.

A more graceful solution is the use of mod_gzip, one of the many additional modules available for Apache. We consider it one of the overlooked gems for designing a high-performance Web server. Using this module, configured file types will be compressed using GZIP-encoding after they've been processed by all of Apache's other modules, and before they're sent to the client. The compressed data that's generated reduces the number of bytes transferred to the client, without any loss in the structure or content of the original, uncompressed document.

You may ask your hosting administrators to install the necessary compression module: mod_deflate (Apache 2.0.x) or mod_gzip (Apache 1.3.x).

Slow down SE crawlers

Search engines may crawl your site and cause a performance degradation. You may slow down the robots crawling your site by adding the following line into robots.txt file (in the root of your web site):

User-Agent: *
Crawl-Delay: 10

Use Content Delivery Networks like MaxCDN

Author: Jon Peters from WebsiteCM.com

(Thank you, Jon, for contributing articles for X-Cart Knowledge Base!)

What is MaxCDN - see here

Setting up a CDN for your medium to large X-Cart site will help improve its loading times across the world by delivering static content from the MaxCDN server located closest to your customer. Google uses site loading times as a factor in search engine ranking so for sites with steady sales and traffic we recommend implementing a CDN like MaxCDN.

Once your CDN has been established, you can integrate x-cart as follows:

Open smarty.php

$smarty->assign("SkinDir",$xcart_web_dir."/skin1");
$smarty->assign("ImagesDir",$xcart_web_dir."/skin1/images");

Replace with: (Be sure to replace CdnUrl.example.com with your CDN Url)

// WCM - MaxCDN Implementation
if ($_SERVER['HTTPS'] != 'on')
{
$smarty->assign("SkinDir","http://CdnUrl.example.com/skin1");
$smarty->assign("ImagesDir","http://CdnUrl.example.com/skin1/images");
}
else
{
$smarty->assign("SkinDir",$xcart_web_dir."/skin1");
$smarty->assign("ImagesDir",$xcart_web_dir."/skin1/images");
}

Performance improvement patches for X-Cart

Improvement: *PERFORMANCE* Languages cache generation is optimized.

This improvement is aimed to resolve the following issue: Index page (home page) loads slow.

X-Cart 4.3or above

For versions from 4.3 branch, download and apply the following patches:

X-Cart 4.4or above

For versions from 4.4 branch, download and apply the following patches:

Note: This improvement patch is already included into X-Cart 4.4.2 release.