Book Image

Instant Magento Performance Optimization How-to

By : Nayrolles Mathieu (USD), Mathieu Nayrolles
Book Image

Instant Magento Performance Optimization How-to

By: Nayrolles Mathieu (USD), Mathieu Nayrolles

Overview of this book

The optimization of an attractive commercial website is a non-trivial task that demands time and knowledge. Optimization is a critical point for all growing businesses because a misconfiguration could make you lose money, a lot of money. If your server is overloaded, a browser that wants to turn into a buyer will not be able to, and you will lose customers. "Instant Magento Performance Optimization How-To" is a practical, hands-on guide that provides you with a number of clear, step-by-step exercises to help you reach a high performance level for your Magento stores and keep your customers satisfied.This book looks at tweaks and tips used to boost your Magento Performance, and breaks down the confusion that surrounds the subject.You will learn how to compress your pages, styles, and scripts by almost 80%. We will also take a look at controversial optimization settings such as Magento core compilation or enabling all caching systems. You will discover new applications that improve performance. If you wish your e-businesses to grow and want to keep your customers satisfied, you definitely need this book.
Table of Contents (7 chapters)


In the open source, e-commerce platforms community, users and developers have only one word to say: Magento! Indeed, in a short period of time, Magento has established itself as the most popular e-commerce platform in the market. Moreover, many developers create Magento extensions that can fit most usual and unusual needs.

Magento Inc. claims that they are trusted by more than 125,000 businesses, including some major brands such as Nike and Lenovo and was downloaded over 3.8 million times. From the beginning, there are two versions of the Magento platform, the Community and the Enterprise version. The Enterprise version has annual fees starting from USD 14,000 (December 2012), while the Community edition remains free. It is likely that the Community version is the most used of both.

One hundred twenty-five thousand merchants all around the world and 3.8 million downloads are quite impressive statistics, but how to explain the gap between people who try to create their own businesses and people who actually have a profitable e-commerce out there? Magento is an advanced e-commerce platform, and advanced also means a complex platform. Like any complex platform for online businesses, Magento configurations must evolve to fit new user requirements and operational needs. The changes resulting from the increasing number of browsers and buyers may degrade the quality of service and the user experience of any e-commerce website. The optimization of an attractive commercial website is a nontrivial task that deserves time and knowledge. Moreover, the optimization is a critical point for all growing businesses, because a misconfiguration could make you lose money, a lot of money. Indeed, if your server is overloaded, even for a short period of time, a browser that wants to turn into a buyer will not be able to do it; and it's good to know that, on an average, a dissatisfied customer will talk to twelve people about his bad experience while a satisfied customer will only talk to three.

There are numerous other causes that lead to giving up Magento or making you lose money, such as getting lost inside the tons of files, being disturbed by the massive object programming style, or becoming tired of trying configurations found online that do not work. However, we will focus on performance optimization.

Despite all these traps, the good news is that there are hundreds of people like you and I, who have made their own mistakes, created best practices, and shared all this knowledge on the Internet.

Instant Magento Performance Optimization How-to has been designed to be a reference for administrators and developers on how to turn your businesses into performances, by reducing a huge amount of time in online research and unsuccessful attempts.

Although the optimization is a nontrivial and complex task, I want this book to be easily accessible for anyone who wants to speed up his Magento; that's why I have spent dozens and dozens of hours in researching, testing, and building simple step-by-step tutorials.

This book will focus on the latest release of the Magento Community Edition, Version 1.7. Various tricks and tips exposed in this book will certainly work with earlier versions, especially Version 1.6, but I can't guarantee it for all of them. Moreover, if your Magento Community version isn't the latest one, we recommend as a first step to upgrade it for optimization, security, and innovation reasons.

What this book covers

Merging CSS files (Must know) shows you how to gather all the CSS files scattered over your Magento, which will optimize the loading time in a way you wouldn't expect.

Merging JavaScript (Must know) shows you how to merge JavaScript files inside a unique file, in the same way as CSS files.

Logging files (Must know) explains that for every main action your Magento has done, it has to write a line on your hard drive in order to help you monitor your e-commerce. Nevertheless, this feature is really resource-consuming.

Compiling (Must know) introduces you to the lookup, which is a process that finds PHP files (that Magento are mainly composed of) in your web server. We can help this process to run faster using compilation.

Managing the index (Must know) introduces you to the index, which is a data structure that accelerates the retrieving process of the information present in your database.

Removing PayPal's logo (Must know) explains how easy it is to make money through PayPal. Unfortunately, retrieving the logo from their website takes a while. That's why we will remove it and display a locally-hosted image instead.

Using the Magento caching system (Must know) introduces you to Magento's built-in caching system for saving frequently asked requests.

Enhancing the expiration date (Should know) shows you that browsers can save some of your website content, such as images and scripts. This recipe explains how to encourage them to save it for a longer time.

Keeping your connections alive (Should know) shows you how customers accede to your e-commerce through HTTP and TCP connections. We will manage to proceed many HTTP connections in one TCP connection.

Storing your sessions in the database (Should know) shows you that when a client comes back to your website after a few days, he will still have information such as shopping carts intact.

Configuring MySQL (Should know) explains how MySQL is provided with settings in order to make it work on every computer. Improve the settings for your hardware.

Using a memory-based filesystem for caching (Become an expert) introduces you to the slowest component of a computer, the hard drive, and how Magento makes massive use of it. This lets you use your available RAM.

Compressing your code – gzip (Become an expert) walks you through the compression algorithms created for plain text that can be used to compress all your codes files.

Installing a PHP accelerator (Become an expert) explains that PHP is a language that can be transformed, on demand, to be understandable by your processors. We can save this transformation.

Clustering (Become an expert) shows you how to configure a set of loosely connected computers working together for handling more and more customers.

Balancing load (Become an expert) explains how to dynamically redirect your customers towards the least loaded servers.

Replicating the database (Become an expert) shows you how to create multiple nodes for storing systems so as to optimize the reading and writing of data.

Checking the configuration (Must know) explains how to identify common misconfigurations.

Clearing caches (Must know) explains how to clear all your caches in order to start afresh.

Logging (Must know) shows you how to find all your log files in your filesystem.

Using template hints (Must know) explains how to display template-related information for debugging purposes.

Using the Profiler (Should know) explains how to use the Profiler. Profiler is a monitoring system used to measure time on your Magento.

Using a debugger (Should know) explains how to analyze your code step-by-step if all the information you have does not tell you where the bugs are.

What you need for this book

The most important prerequisite you must have before reading this book is the kind of courage that enables you to get away with murder when you are inside a management system.

A test subject for testing and optimization is of course required, and it will be a plus if the reader is accustomed to the technical backend console; but it's not necessary.

In order to follow the optimizations present in this book, you will need a copy of your actual website or a fresh installation of the Magento Community Edition with the sample data. Of course, you can apply these optimizations on your live websites, but at your own risk. Indeed, beginning such optimizations can (always) create some mess.

Who this book is for

This book is specially made for Magento administrators and users who are familiar with using the backend technical console, but people who are new to anything beyond this and wish to optimize their online store for increasing performance can also read this book.

Anyway, if you are interested in building a robust e-commerce business and intend to really satisfy customers beyond the average, you definitely need to read this book.


In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "The Magento Core adds an HTML <div> tag before each file."

A block of code is set as follows:

    <dbname>|<![CDATA[NEW DATABASE_NAME]]>|</dbname>|
    <initStatements>|<![CDATA[SET NAMES utf8]]>|</initStatements>|

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

    <initStatements><![CDATA[SET NAMES utf8]]></initStatements>

Any command-line input or output is written as follows:

sudo pecl install xdebug

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Finally click on the Submit button."


Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on or e-mail .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.


Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from


Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.


You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.