Before we start talking about increasing performance, it is crucial to define what you want to improve, how, and why. Any optimization means fixing or optimizing the project code or increasing your server capacity, and this already affects the financial side.
All the recommendations and actions for optimizing projects presented in this article can disrupt your store operation. Therefore, we ask you to be as careful as possible in your actions. If something went wrong, cancel your previous actions and seek help from the specialists of CS-Cart or your hosting provider with a description of what caused the problem.
Update CS-Cart or Multi-Vendor, all themes and add-ons
Updating the CS-Cart core, themes, and add-ons is important because the new versions contain performance patches, patches to improve and optimize workflows and to fix bugs and vulnerabilities.
Update the PHP version and take advantage of its full potential
Find out what the maximum supported PHP version is available for your current version of CS-Cart or Multi-Vendor.
We conducted load tests for a default CS-Cart theme without third-party add-ons. These tests show that project performance can be increased by updating the PHP version:
Please, note that not all add-ons and CS-Cart versions support the latest PHP versions causing the unavailability of your project. Before updating your live store, check the update on your local computer or on the staging server. Alternatively, you can refer to developers.
How does the PHP app work? PHP opens the files with code, aggregates them, analyzes, assigns tokens, compiles, and then runs them. As there are lots of such files, the process of opening, reading, and compiling them can be resource-intensive. But since the files do not change so often, you don’t need to compile them every time. It is more rational to do it once, cache the result, and then refer to it.
This is exactly what OPcache does. It saves the result of the compilation to the cache so that it can be used later instead of generating it over and over again. Thus, it makes PHP faster by eliminating the compilation process. And when your code changes, OPcache invalidates the cache and compiles it again. All of it is done without the need to configure it!
FastCGI is one of the options for connecting PHP to a web server. PHP-FPM (FastCGI container for PHP) and NGINX are interoperable by default and configured for maximum performance with each other without additional layers.
Some people like to use Apache + mod_php module as a web server or even a worse combination—NGINX + Apache (mod_php) + PHP. Indeed, Apache allows using the .htaccess files loved by admin beginners, but it affects the performance by about 3-7% compared to NGINX + PHP-FPM configuration. We recommend avoiding Apache since its initial configuration is vulnerable to a range of attacks.
Limit PHP and explore every parameter you plan to change
You get it right. It may seem strange but setting PHP to the maximum is not a good decision. If you allot more capacity or do not limit the runtime for some processes, other system components can be deprived of resources or they will compete with each other till OOM Killer kills them.
We do not recommend setting the script execution time for more than 1 minute for conventional processes. At this, such processes as import, export, and updates can last long in CS-Cart. Just for these processes, an increase of “timeouts” on the PHP and MySQL sides may be required.
It’s true, there may be complex processes that require increased execution time. However, these processes often can be divided into smaller processes and tasks. Ask developers to decompose long and heavy processes into smaller ones to enhance the entire system and your particular project reliability.
Increase max_execution_time only in extreme cases.
Do not set this parameter too high, as OOM Killer will then come for all PHP at once.
Also, do not forget that you also have MySQL and some other components—they also need memory, and the system itself needs memory for its operation.
Increase memory_limit only in extreme cases.
Update and optimize the database (MySQL)
Convert all tables from MyISAM to InnoDB
If the database queries are too long and heavy, converting will allow locking only the rows where the operation is going instead of locking the whole table. Ask your host or system admin to migrate tables from MyISAM to InnoDB.
Here are the main differences between InnoDB and MyISAM:
- InnoDB implements row-level locking while MyISAM locks at the table level only.
- InnoDB applies a so-called ‘referential integrity’ which includes support of foreign key constraints (RDBMS), and MyISAM doesn’t (DMBS).
- InnoDB is more reliable as it uses a transaction log for auto-recovery, and MyISAM doesn’t.
Optimize the MySQL settings
As the majority of parameters need to be set up based on the RAM capacity, for the sake of this article, we won’t be able to specify accurate values. However, you will get the general direction to consider and study further.
A long database query is the troublemaking query. It should be optimized or rewritten. Avoid exceeding the query execution time: if a query is bad, it will cause problems for other queries and processes. It is extremely rare that this parameter needs to be increased, but we recommend reverting this parameter to its original state after all the heavy operations have been completed.
It is quite often when the long queries are caused by their poor design. I’ve already mentioned this problem in one of my posts.
Check configuration using MySQLtuner
Increase server capacity
Not all website performance problems can be solved by increasing the PHP parameters, MySQL configuration files, or updating the server software. Sometimes there comes a time when you need to think about increasing the capacity of your server or your current plan with your hosting provider. This may involve installing additional add-ons, increasing the number of products, or simply increasing the number of visitors to your site.
We also recommend increasing server capacity during sales and marketing campaigns.
Use the HTTP/2 connection (and TLS 1.3)
Here, performance goes side by side with the security. The HTTP/2 Protocol (which is available for https connections only) is much more optimized compared to HTTP 1.1. Thus, simply implementing this specification, you will considerably enhance your store performance.
CS-Cart tweaks and options
If, after making changes, your project becomes unavailable, cancel the changes and contact CS-Cart technical support and your hoster. They will help you with the setup.
GD and Imagick are two different PHP extensions to handle graphics. Both modules are quite similar, but Imagick gives better results when creating thumbnail images. At this, it consumes less memory.
To enable Imagick, change the tweak value to imagick in the $config[‘tweaks’] array of the config.local.php file. See this screenshot.
Also note that if you have “auto” in your config.local.php file opposite image_resize_lib, then once you have imagick installed, it will be used by default.
Enable APCu for cache and Redis for storing sessions
We recommend using APCu for storing cache and Redis—for storing sessions in CS-Cart. This separation will reduce the load on the database and the disk, but it may add a point of failure in the form of an extra service that needs to be additionally tracked. And the cache transfer to APCu will augment the PHP requirements :)
$config[‘session_backend’] = ‘redis’;
Enabling these parameters in the config file requires APCu pre-configured in PHP 7.0+ and Redis on your server. Before changing the configuration file, make sure that APCu and Redis are available for use on the server. If you are not sure or in doubt, contact your system administrator or hoster to configure them.
Use mysqldump for backup
Mysqldump is a server extension used by all contemporary hosts. All admins recommend using it to create database backups.
To enable it, add the backup_db_mysqldump parameter with the true value to the $config[‘tweaks’] array or change the tweak value in the config.local.php file. See this screenshot.
Implement a backend lock in the cache generation processes
The latest versions of CS-Cart offer users an opportunity to lock the backend for cache generation if the generation process is being run. You can enable it using the $config[‘lock_backend’] = ‘database’; parameter in the config.local.php. file.
By doing so, you can avoid major problems during cache generation.
How to find and fix problems with CS-Cart performance without programming skills
You can find tips for quick optimization and finding performance issues for your CS-Cart and CS-Cart Multi-Vendor project without programming skills in this post.
And we also have an article with important metrics telling about factors affecting the site speed.