Difference between revisions of "X-Cart:Performance tips"

From X-Cart 4 Classic
Jump to: navigation, search
m
 
(29 intermediate revisions by 5 users not shown)
Line 1: Line 1:
There are several options that may help you to speed up site. Try them out first.
+
If your online store started getting slow, you can try speeding it up. This article gives an extensive list of tweaks that you can try applying to your store and a tool for measuring the performance optimization results.
  
=== Moving images to file system. For v.3.5.x and 4.0.x===
+
=== Optimization settings ===
  
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.
+
{{XC 4.4}}
  
Each time you do <tt><img src="image.php?imageid=345"></tt> 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).
+
Since version 4.4.2, X-Cart features 9 new options in the <u>Optimization settings</u> section. (To open the <u>Optimization settings</u> section, select '''Settings''' -> '''General''' on the Administrative menu and then scroll down to ''Optimization settings''.)
  
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.
+
If you experience performance problems, you may want to try turning off some or all of these switches.
  
After that modify original <tt>.htaccess</tt> file (in <tt>/files</tt> directory) and change the code to:
+
{{Note1|Be aware that certain options boost the performance at the cost of disabling some features. To find out what you get and what you give up, place the mouse pointer over the question mark icon by an option and read the hint that appears.}}
 +
 
 +
The '''Use speed-up tool for Javascript''' and '''Use speed-up tool for CSS''' check boxes enable the optimization for the operations of assembling and displaying the code in JavaScript and CSS. For more information on using these options, please read [[X-Cart:CSS_and_JavaScript_optimization|CSS and JavaScript optimization]].
 +
 
 +
Use caching frequently used data to speed up future requests for that data. The caching options are self-descriptive, but take a look at the note to see when to use and when to avoid using certain options.
 +
 
 +
'''Generate X-Cart cache every N hour(s).''' The recommended value is 24. To disable using cache, edit <u>config.php</u> and change the value of the <tt>USE_DATA_CACHE</tt> constant to false.
 +
 
 +
'''Use cache for language variables.''' Use this option if you have a lot of memory dedicated to your PHP engine. This option can slow down your shop pages in some cases. Please, check your pages before enabling this option in the production mode. If you have a multi-language store, make sure that all the labels used in it are defined for each language if this option is enabled.
 +
 
 +
Disable unnecessary logs and checks.
 +
 
 +
'''Do not check if templates are changed (Smarty compile_check).''' Once the application is put into production (i.e. the templates are not going to change any more), the compile check step is no longer necessary. Just keep in mind that if you change a template file while this option is enabled, you will ''not'' see the change, as the template is not going to be recompiled. Enable this option for the maximium performance.
 +
 
 +
'''Do not delete empty strings in templates.''' The recommended value is ON. Prior to showing a compiled Smarty template, you can choose to remove two or more successive empty strings, if there are any. With a large number of templates to be displayed, this can cut the productivity. Disable this option if you have problems with the appearance of your page.
 +
 
 +
'''Do not log changes in PHP configuration settings.''' The recommended value for production mode is ON. Disable this option if you want to track changes in PHP configuration settings. The changes will be logged in files like <u>var/log/x-errors_env-<date>.php</u>. This can be useful during the development or during the problem research phase.
 +
 
 +
'''Check only main category condition for products selection and product search.''' You may want to enable this option if you have many additional product categories.
 +
 
 +
'''Do not check product's category availability and product's category membership on all the product related pages.''' If you select this check box, you will have to define product availability and membership for each product individually. This affects the Feature comparison product list, Featured products, Product search, Special offer pages and Manufacturer products. Enable this option if you have many categories and problems with the performance of your store. Please note that the 'Order by' field defined on the category details page will not be used with this option enabled.
 +
 
 +
Please note that in some cases selecting this option can rather slow down your shop pages instead of speeding them up, so please check your pages before enabling this option in the production mode.
 +
 
 +
'''Use simple sorting by ''productid'' on all the product related pages.''' Enable this option if you have problems with the performance of your store. Please note that with this option enabled the ''Sort by'' feature will not be available on all the product pages. This affects the Feature Comparison product list, Featured products, Product search, Special offer pages and Manufacturer products.
 +
 
 +
'''Do not use product international descriptions on all the product related pages.''' The recommended value for a single-language store is ON. Enable this option to search in the default language. Please note that with this option enabled international descriptions will not be used on all the product pages. This affects the Feature Comparison product list, Featured products, Product search, Special offer pages and Manufacturer products.
 +
 
 +
=== Caching templates ===
 +
 
 +
To further boost the performance of your store, in your templates use <tt>{include_cache file="some_template.tpl"}</tt> instead of <tt>{include file="some_template.tpl"}</tt>. This caches the template file and then serves the cached copy instead of generating a new one every time the template is requested in the future.
 +
 
 +
{{Note1|To ensure the correct appearance of your template, make sure to pass all the variables used in the template as parameters of the <tt>include_cache()</tt> function.}}
 +
 
 +
=== Checking database integrity ===
 +
 
 +
Run this check periodically, as garbage in the database can significantly drop the performance of the entire store. For more information, please read [[X-Cart:Advanced_Tools#Check_Database_Integrity|Checking database integrity]].
 +
 
 +
=== Caching database queries ===
 +
 
 +
With SQL queries being cached, every time the database engine reads a query, it caches the query data in the memory and then serves that data from the memory instead of retrieving it from the database all over, thus boosting the query performance. You can enable SQL query cache by editing the setting in <u>config.php</u>.
 +
 
 +
=== Checking MD5 of compiled templates ===
 +
 
 +
Checking MD5 of compiled templates prevents the use of unauthentic templates, which could be potentially harmful. Nevertheless, you can disable this check and thus boost the overall performance of your store For more information on using this option, please read [[X-Cart:Security_Options|Security options]].
 +
 
 +
=== Redirecting customers to regular HTTP ===
 +
 
 +
Once switched to HTTPS, customer continues to browse the store over the secure protocol. HTTPS is known to be slower than HTTP, as it adds handshake and data encryption to the regular data exchange routine; plus, it doesn't allow caching. You can enable redirecting customers to the regular HTTP on pages where increased security is not required and thus boost the performance of the store. For more information, please read [[X-Cart:Security_Options|Security options]].
 +
 
 +
=== Moving images to file system ===
 +
 
 +
Each image that is to appear on any page of your store opens a new connection to your store's database. Even if it's only one image per page, doubling connections to the database isn't fun to think about.
 +
 
 +
Every time you do things like <tt><img src="image.php?imageid=345"></tt>, you make yet another 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. The very connection to the database, without executing any queries, takes a significant amount of server time (more in terms of processing cycles than the actual time).
 +
 
 +
Storing your images in database tables is not recommended from the performance point of view. Our advice is to place images in the file system. This can be easily done by modifying a single setting in the control panel. For details, please study the [[X-Cart:Images Location Management]] page.
 +
 
 +
After that modify the original <tt>.htaccess</tt> file (in <tt>/files</tt> directory) and replace its code with:
  
 
<pre>
 
<pre>
Line 18: Line 76:
 
</pre>
 
</pre>
  
===Toggling off tracking statistics===
+
===Toggling off 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 <u>Advanced Statistics</u>. This module significantly slows down X-Cart by storing statistical information in the database.
+
It is strongly recommended that 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 <u>Advanced Statistics</u> module. This module significantly slows down X-Cart when storing statistic data in the database.
  
 
'''In X-Cart v3.5.x or later:'''
 
'''In X-Cart v3.5.x or later:'''
Line 40: Line 98:
 
</pre>
 
</pre>
  
{{Note1|Note: As an alternative to "Advanced Statistics" module, you can enable the [[X-Cart:Google_Analytics | "Google Analytics"]] module to use Google Analytics system with your store.}}
+
{{Note | A good alternative to the "Advanced Statistics" module is the [[X-Cart:Google_Analytics | "Google Analytics"]] module that uses Google Analytics with your store.}}
  
 
===Cleaning statistics tables===
 
===Cleaning statistics tables===
Line 46: Line 104:
 
For v.3.5.x and 4.0.x.
 
For v.3.5.x and 4.0.x.
  
In the admin back-end of x-cart: ‘Summary’ page - > ‘Statistics clearing’.
+
In the Admin area of your X-Cart store, select: ‘Summary’ page - > ‘Statistics clearing’.
  
For v.4.1.x: Statistics can be cleared via admin area: 'Summary' page, section 'Tools/Statistics clearing'.
+
For v.4.1.x: Statistics can be cleared via the Admin area: 'Summary' page, section 'Tools/Statistics clearing'.
  
 
=== Optimizing SQL tables===
 
=== 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.
+
X-Cart stores its data in database tables, and over time these tables could become fragmented/less organized. This is especially the case when you make changes to the data in your store's database tables directly.
  
 
'''In X-Cart v.4.1.x or later:'''
 
'''In X-Cart v.4.1.x or later:'''
Line 60: Line 118:
 
'''In X-Cart v.3.5.x and 4.0.x:'''
 
'''In X-Cart v.3.5.x and 4.0.x:'''
  
Execute the following sql query for each x-cart table
+
Execute the following SQL query for each X-Cart table (<table_name> needes to be replaced with the actual name of the table):
  
 
<pre>
 
<pre>
Line 66: Line 124:
 
</pre>
 
</pre>
  
where replace <table_name> with the name of a table. You will find the list of x-cart tables using the next sql query:
+
You can get the list of X-Cart table names by executing the following SQL query:
  
 
<pre>
 
<pre>
 
SHOW TABLES;
 
SHOW TABLES;
 
</pre>
 
</pre>
 +
 +
==== Cron-based scheduling of SQL table optimization tasks for X-Cart versions 4.6.0 and later ====
 +
If your store is based on X-Cart 4.6.0 or later, it is recommended to set up a cron job to automatically launch the MySQL table optimization routine on a regular schedule.
 +
 +
For example, the following crontab configuration (full_path_xcart_web_dir needs to be replaced with the actual path to your X-Cart directory as seen from the Web, <php_bin_path> - with your actual php binary path):
 +
<pre>
 +
0 2,3,4 * * * (cd full_path_xcart_web_dir/tools;<php_bin_path>/php maintenance_jobs.php)
 +
</pre>
 +
will launch the optimization routine every night at 2:00, 3:00 and 4:00 a.m.
 +
 +
The following crontab configuration:
 +
<pre>
 +
0 2,3,4 * * 6,7 (cd full_path_xcart_web_dir/tools;<php_bin_path>/php maintenance_jobs.php)
 +
</pre>
 +
will launch the optimization routine at 2:00, 3:00 and 4:00 a.m. on weekends.
 +
 +
The above examples are for console users; if you are using a control panel like cPanel or Plesk, the cron job schedule can be easily set up using the standard control panel interface.
 +
 +
When deciding on the schedule for SQL optimization tasks on your site, be sure to choose the times when your site has the least number of visitors.
 +
 +
=== Optimizing CSS ===
 +
 +
To optimize CSS, you can take advantage of the <tt>load_defer</tt> and <tt>load_defer_code</tt> 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 [[X-Cart:CSS_and_JavaScript_optimization|CSS and JavaScript Optimization]].
 +
 +
=== Optimizing JavaScript ===
 +
 +
To optimize JavaScript, you can also use the <tt>load_defer</tt> and <tt>load_defer_code</tt> Smarty tags to enable assembling and displaying cached JavaScript code. For further details on using these tags for JavaScript, please refer to [[X-Cart:CSS_and_JavaScript_optimization|CSS and JavaScript Optimization]].
 +
 +
===Caching images ===
 +
 +
When user views the 'Product details' page, X-Cart serves the reduced-size copy 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  [[X-Cart:Advanced_Tools|Advanced Tools]].
  
 
===Generating HTML catalog===
 
===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.
+
Additionally, it is recommended to generate an HTML catalog. With an HTML catalog available, your customer zone appears as a set of static pages, linked together without the actual PHP scripts execution and database queries. This could significantly lower the load on your server.
  
=== Compression of html source===
+
=== Compressing HTML source ===
  
 
You may try to put the following lines in the php.ini file:
 
You may try to put the following lines in the php.ini file:
Line 98: Line 187:
 
=== Installing Zend Optimizer===
 
=== Installing Zend Optimizer===
  
The [http://www.zend.com/ 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.
+
[https://www.zend.com/ 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 can run them on your server while decrypting and running them on-the-fly while increasing the runtime performance.
  
 
=== Install additional Apache modules (optional)  ===
 
=== 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.
+
The idea behind GZIP-encoding documents is very straightforward. Take a file to be transmitted to the browser, and send a compressed version of the file, 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.
+
In Apache, this can be achieved using the Content Negotiation, which requires that two separate sets of HTML files would be generated: one for the browsers that can handle GZIP-encoding, and the other — for those that cannot. This solution sends GZIP-encoded files to browsers that understand them, while disabling the compression for 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.
+
A more graceful solution is to use mod_gzip, one of the many additional modules available for Apache. We consider it to be one of the overlooked gems for designing a high-performance Web server. This module compresses files of certain types after they've been processed by all the other Apache's modules and before they are sent to the browser. The compressed data reduces the number of bytes transferred to the browser, 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: <tt>[http://httpd.apache.org/docs/2.0/mod/mod_deflate.html mod_deflate]</tt> (Apache 2.0.x) or <tt>[http://sourceforge.net/projects/mod-gzip/ mod_gzip]</tt> (Apache 1.3.x).
+
You may ask your hosting administrators to install the necessary compression module: <tt>[https://httpd.apache.org/docs/2.0/mod/mod_deflate.html mod_deflate]</tt> (Apache 2.0.x) or <tt>[https://sourceforge.net/projects/mod-gzip/ mod_gzip]</tt> (Apache 1.3.x).
  
 
=== Slow down SE crawlers===
 
=== 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):
+
Search engines crawling your site could considerably drop its performance. You can slow down the crawlers by adding the following commands to the robots.txt file (in the root of your web site):
  
 
<pre>
 
<pre>
Line 122: Line 211:
  
 
Author: [http://www.websitecm.com/articles/x-cart-tutorials/how-to-setup-maxcdn-on-x-cart/?partner=marketplace Jon Peters from WebsiteCM.com]
 
Author: [http://www.websitecm.com/articles/x-cart-tutorials/how-to-setup-maxcdn-on-x-cart/?partner=marketplace Jon Peters from WebsiteCM.com]
 +
 +
(Thank you, Jon, for contributing articles for X-Cart Knowledge Base!)
 +
 +
What is MaxCDN  - [https://marketplace.x-cart.com/Marketing/MaxCDN-for-X-Cart 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.
 
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:
 
Once your CDN has been established, you can integrate x-cart as follows:
 +
 +
1) If you use 4.3.x or older:
  
 
Open smarty.php
 
Open smarty.php
Line 150: Line 245:
 
}
 
}
 
</pre>
 
</pre>
 +
 +
2) If you use 4.4.x
 +
 +
Open smarty.php
 +
 +
<pre>
 +
$smarty->assign('ImagesDir',        $xcart_web_dir . $smarty_skin_dir . '/images');
 +
$smarty->assign('SkinDir',          $xcart_web_dir . $smarty_skin_dir);
 +
</pre>
 +
 +
Replace with:
 +
(Be sure to replace CdnUrl.example.com with your CDN Url)
 +
 +
<pre>
 +
// WCM - MaxCDN Implementation
 +
if ($_SERVER['HTTPS'] != 'on')
 +
{
 +
$smarty->assign('ImagesDir',        "http://CdnUrl.example.com" . $smarty_skin_dir . '/images');
 +
$smarty->assign('SkinDir',          "http://CdnUrl.example.com" . $smarty_skin_dir);
 +
}
 +
else
 +
{
 +
$smarty->assign('ImagesDir',        $xcart_web_dir . $smarty_skin_dir . '/images');
 +
$smarty->assign('SkinDir',          $xcart_web_dir . $smarty_skin_dir);
 +
}
 +
</pre>
 +
 +
3) It is also recommended (optionally):
 +
 +
* in smarty.php, to edit the following:
 +
 +
$smarty->assign('AltImagesDir'...
 +
$smarty->assign('AltSkinDir'....
 +
 +
similarly to ImagesDir/SkinDir.
 +
 +
* to edit the function func_image_cache_get_image from include/func/func.image.php replacing $current_location with CDN URL.
 +
 +
=== 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.
 +
 +
{{XC_4.3}}
 +
 +
For versions from 4.3 branch, download and [[X-Cart:Applying_Patches | apply]] the following patches:
 +
 +
* [[File:Lang_cache.sql]]
 +
* [[File:DIFF_lang_cache.patch]]
 +
 +
{{XC_4.4}}
 +
 +
For versions from 4.4 branch, download and [[X-Cart:Applying_Patches | apply]] the following patches:
 +
 +
* [[File:Lang_cache.sql]]
 +
* [[File:DIFF_54127.patch]]
 +
 +
{{Note | This improvement patch is already included into X-Cart 4.4.2 release.}}
 +
 +
=== Real-time shipping calculation & slow cart/checkout page ===
 +
 +
Sometimes using real-time shipping calculation might cause the cart/checkout page to slow down. Try disabling the [[X-Cart:Shipping_Options#Real-time_shipping_options | real-time shipping calculation option]] in your store temporarily, then check the performance of the cart/checkout page.
 +
 +
If that is the case, [[X-Cart:Testing_Your_Store's_Ability_to_Receive_Real-time_Shipping_Rates | test real-time shipping calculation]] using different options for the [[X-Cart:General_Options#Miscellaneous | "Preferred HTTPS module"]], and finally set the option which provides the best performance results.
 +
 +
=== Miscellaneous ===
 +
 +
You can further assess the effect made by adjusting certain settings on the page load rate using ''Firebug'', a FireFox extension. For more information on installing and using this tool, please visit [http://getfirebug.com/wiki/index.php/Net_Panel#Timeline Firebug website].
 +
 +
==See also==
 +
 +
* [[X-Cart:X-Cart_Benchmark_report_tool|X-Cart Benchmark report tool]]
  
 
[[Category:Troubleshooting]]
 
[[Category:Troubleshooting]]
 
[[Category:X-Cart user manual]]
 
[[Category:X-Cart user manual]]

Latest revision as of 17:45, 22 July 2020

If your online store started getting slow, you can try speeding it up. This article gives an extensive list of tweaks that you can try applying to your store and a tool for measuring the performance optimization results.

Optimization settings

X-Cart 4.4or above

Since version 4.4.2, X-Cart features 9 new options in the Optimization settings section. (To open the Optimization settings section, select Settings -> General on the Administrative menu and then scroll down to Optimization settings.)

If you experience performance problems, you may want to try turning off some or all of these switches.

Be aware that certain options boost the performance at the cost of disabling some features. To find out what you get and what you give up, place the mouse pointer over the question mark icon by an option and read the hint that appears.

The Use speed-up tool for Javascript and Use speed-up tool for CSS check boxes enable the optimization for the operations of assembling and displaying the code in JavaScript and CSS. For more information on using these options, please read CSS and JavaScript optimization.

Use caching frequently used data to speed up future requests for that data. The caching options are self-descriptive, but take a look at the note to see when to use and when to avoid using certain options.

Generate X-Cart cache every N hour(s). The recommended value is 24. To disable using cache, edit config.php and change the value of the USE_DATA_CACHE constant to false.

Use cache for language variables. Use this option if you have a lot of memory dedicated to your PHP engine. This option can slow down your shop pages in some cases. Please, check your pages before enabling this option in the production mode. If you have a multi-language store, make sure that all the labels used in it are defined for each language if this option is enabled.

Disable unnecessary logs and checks.

Do not check if templates are changed (Smarty compile_check). Once the application is put into production (i.e. the templates are not going to change any more), the compile check step is no longer necessary. Just keep in mind that if you change a template file while this option is enabled, you will not see the change, as the template is not going to be recompiled. Enable this option for the maximium performance.

Do not delete empty strings in templates. The recommended value is ON. Prior to showing a compiled Smarty template, you can choose to remove two or more successive empty strings, if there are any. With a large number of templates to be displayed, this can cut the productivity. Disable this option if you have problems with the appearance of your page.

Do not log changes in PHP configuration settings. The recommended value for production mode is ON. Disable this option if you want to track changes in PHP configuration settings. The changes will be logged in files like var/log/x-errors_env-<date>.php. This can be useful during the development or during the problem research phase.

Check only main category condition for products selection and product search. You may want to enable this option if you have many additional product categories.

Do not check product's category availability and product's category membership on all the product related pages. If you select this check box, you will have to define product availability and membership for each product individually. This affects the Feature comparison product list, Featured products, Product search, Special offer pages and Manufacturer products. Enable this option if you have many categories and problems with the performance of your store. Please note that the 'Order by' field defined on the category details page will not be used with this option enabled.

Please note that in some cases selecting this option can rather slow down your shop pages instead of speeding them up, so please check your pages before enabling this option in the production mode.

Use simple sorting by productid on all the product related pages. Enable this option if you have problems with the performance of your store. Please note that with this option enabled the Sort by feature will not be available on all the product pages. This affects the Feature Comparison product list, Featured products, Product search, Special offer pages and Manufacturer products.

Do not use product international descriptions on all the product related pages. The recommended value for a single-language store is ON. Enable this option to search in the default language. Please note that with this option enabled international descriptions will not be used on all the product pages. This affects the Feature Comparison product list, Featured products, Product search, Special offer pages and Manufacturer products.

Caching templates

To further boost the performance of your store, in your templates use {include_cache file="some_template.tpl"} instead of {include file="some_template.tpl"}. This caches the template file and then serves the cached copy instead of generating a new one every time the template is requested in the future.

To ensure the correct appearance of your template, make sure to pass all the variables used in the template as parameters of the include_cache() function.

Checking database integrity

Run this check periodically, as garbage in the database can significantly drop the performance of the entire store. For more information, please read Checking database integrity.

Caching database queries

With SQL queries being cached, every time the database engine reads a query, it caches the query data in the memory and then serves that data from the memory instead of retrieving it from the database all over, thus boosting the query performance. You can enable SQL query cache by editing the setting in config.php.

Checking MD5 of compiled templates

Checking MD5 of compiled templates prevents the use of unauthentic templates, which could be potentially harmful. Nevertheless, you can disable this check and thus boost the overall performance of your store For more information on using this option, please read Security options.

Redirecting customers to regular HTTP

Once switched to HTTPS, customer continues to browse the store over the secure protocol. HTTPS is known to be slower than HTTP, as it adds handshake and data encryption to the regular data exchange routine; plus, it doesn't allow caching. You can enable redirecting customers to the regular HTTP on pages where increased security is not required and thus boost the performance of the store. For more information, please read Security options.

Moving images to file system

Each image that is to appear on any page of your store opens a new connection to your store's database. Even if it's only one image per page, doubling connections to the database isn't fun to think about.

Every time you do things like <img src="image.php?imageid=345">, you make yet another 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. The very connection to the database, without executing any queries, takes a significant amount of server time (more in terms of processing cycles than the actual time).

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

After that modify the original .htaccess file (in /files directory) and replace its code with:

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

Toggling off statistics

It is strongly recommended that 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 Advanced Statistics module. This module significantly slows down X-Cart when storing statistic data 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: A good alternative to the "Advanced Statistics" module is the "Google Analytics" module that uses Google Analytics with your store.

Cleaning statistics tables

For v.3.5.x and 4.0.x.

In the Admin area of your X-Cart store, select: ‘Summary’ page - > ‘Statistics clearing’.

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

Optimizing SQL tables

X-Cart stores its data in database tables, and over time these tables could become fragmented/less organized. This is especially the case when 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 (<table_name> needes to be replaced with the actual name of the table):

OPTIMIZE TABLE <table_name>;

You can get the list of X-Cart table names by executing the following SQL query:

SHOW TABLES;

Cron-based scheduling of SQL table optimization tasks for X-Cart versions 4.6.0 and later

If your store is based on X-Cart 4.6.0 or later, it is recommended to set up a cron job to automatically launch the MySQL table optimization routine on a regular schedule.

For example, the following crontab configuration (full_path_xcart_web_dir needs to be replaced with the actual path to your X-Cart directory as seen from the Web, <php_bin_path> - with your actual php binary path):

0 2,3,4 * * * (cd full_path_xcart_web_dir/tools;<php_bin_path>/php maintenance_jobs.php)

will launch the optimization routine every night at 2:00, 3:00 and 4:00 a.m.

The following crontab configuration:

0 2,3,4 * * 6,7 (cd full_path_xcart_web_dir/tools;<php_bin_path>/php maintenance_jobs.php)

will launch the optimization routine at 2:00, 3:00 and 4:00 a.m. on weekends.

The above examples are for console users; if you are using a control panel like cPanel or Plesk, the cron job schedule can be easily set up using the standard control panel interface.

When deciding on the schedule for SQL optimization tasks on your site, be sure to choose the times when your site has the least number of visitors.

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 the reduced-size copy 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 recommended to generate an HTML catalog. With an HTML catalog available, your customer zone appears as a set of static pages, linked together without the actual PHP scripts execution and database queries. This could significantly lower the load on 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

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 can run them on your server while decrypting and running them on-the-fly while increasing the runtime performance.

Install additional Apache modules (optional)

The idea behind GZIP-encoding documents is very straightforward. Take a file to be transmitted to the browser, and send a compressed version of the file, 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 the Content Negotiation, which requires that two separate sets of HTML files would be generated: one — for the browsers that can handle GZIP-encoding, and the other — for those that cannot. This solution sends GZIP-encoded files to browsers that understand them, while disabling the compression for dynamically-generated pages.

A more graceful solution is to use mod_gzip, one of the many additional modules available for Apache. We consider it to be one of the overlooked gems for designing a high-performance Web server. This module compresses files of certain types after they've been processed by all the other Apache's modules and before they are sent to the browser. The compressed data reduces the number of bytes transferred to the browser, 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 crawling your site could considerably drop its performance. You can slow down the crawlers by adding the following commands to the 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:

1) If you use 4.3.x or older:

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");
}

2) If you use 4.4.x

Open smarty.php

$smarty->assign('ImagesDir',        $xcart_web_dir . $smarty_skin_dir . '/images');
$smarty->assign('SkinDir',          $xcart_web_dir . $smarty_skin_dir);

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

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

3) It is also recommended (optionally):

  • in smarty.php, to edit the following:

$smarty->assign('AltImagesDir'... $smarty->assign('AltSkinDir'....

similarly to ImagesDir/SkinDir.

  • to edit the function func_image_cache_get_image from include/func/func.image.php replacing $current_location with CDN URL.

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.

Real-time shipping calculation & slow cart/checkout page

Sometimes using real-time shipping calculation might cause the cart/checkout page to slow down. Try disabling the real-time shipping calculation option in your store temporarily, then check the performance of the cart/checkout page.

If that is the case, test real-time shipping calculation using different options for the "Preferred HTTPS module", and finally set the option which provides the best performance results.

Miscellaneous

You can further assess the effect made by adjusting certain settings on the page load rate using Firebug, a FireFox extension. For more information on installing and using this tool, please visit Firebug website.

See also