How We Reduced Magento’s Footprint By Over 200%
One of the inherent problems with any content-manageable website (one that gives its owners the power to make changes to what appears on it without getting a nerd involved), no matter whether it’s WordPress, Magento, Joomla, Drupal, etc. is that the addition of data is a one-way process.
What this means is that, over the years, data is added to the site, images are continuously uploaded, etc… Some of these products and images will stay forever but for sites with a short lifespan for products, or sites with lots of new products coming in every season, this quickly builds up.
Unless you delete old products and data as you go, to prevent them from being shown to the world, they will remain behind the scenes on your website.
For business owners, there’s usually little time or reason to carry out any regular maintenance and reduce some of the space your site’s taking up.
This is where we found ourselves recently. Following an upgrade from Magento 1 to Magento 2 (including a migration of all of the data from years before), one of our client’s sites was now sat on a server with a 123.5Gb footprint. Resource is money, of course, and the use of the disk space to house this large website was costing a small fortune.
We subsequently realised that in a former life this site had been creating three versions of each image uploaded, into three different dimensions, and with Magento then dynamically creating cached versions of these files it meant that each image uploaded resulted in seven new images being created on the server.
To resolve this issue, we developed a script that scanned the hosting environment, interrogating all of the sub-directories that Magento uses to house images, and then compared that list with what was in the site’s database (Magento using several tables to store product images).
If the file wasn’t listed in the database then it didn’t survive the cull!
On this site, despite using direct database queries for speed, it took the best part of five days (leaving it running 24 hours) to complete.
By the time it finished the disk usage was down to 41Gb – a saving of over 200% and a significant reduction in hosting costs.
With more and more Magento 1 sites choosing to upgrade to Magento 2 at the moment, and more on the way, this simple script could end up saving money for a lot of our clients – and who doesn’t like saving money?