Optimizing Your Magento Shopping Cart

| August 19, 2013 | 0 Comments

Magento Shopping Cart Issue

Anyone that knows me knows that I love the Magento Shopping Cart system.  It’s just brilliant.  However its brilliance comes with a price and that price is computing power.  We all know Magento requires a lot of specifics for it to run properly.  I first started running Magento projects on my servers, along with my regular clients, but found quickly that with having 5 Magento shopping carts running on 1 server, with approx. 5000 products each I had to upgrade my ram continuously just so my server wouldn’t crash.  Even then my server slowed right down, and the Magento Shopping Carts, where running slower than the mail.  It took an average of 10-20 seconds for one page to load, which was completely unacceptable.  I had to find another solution and fast.

The Magento Shopping Cart Hosting Solution

My solution was to find a Magento specific hosting company to run my Magento websites, and I found it www.siteground.com.   Now the reason why I like running my own servers is because it gives me full control over my websites than shared hosting would.  I never run into the issue of hearing “well that’s all your package allows you’ll have to upgrade if you want more blah blah blah…”

Siteground.com offered $3 per month for its Magento specific hosting.  I had my doubts but thought I would give it a try – so I moved 1 site over as a test site to exactly see how good their support team was as well as their server capabilities.  They actually offer free site transfers, and thought why not?  Lets let them do all the leg work if they are offering and I must say I was pretty impressed, they moved it over flawlessly, no issues and I was happy.  Once the domain propagated and I was able to see my Magento Shopping Cart of 5000 products running on this Magento specific hosting plan for only $3 a month I was again blown away.   This website that took 10-20 seconds to load per page on my server was loading pages in less than 1 sec.  Boom there’s a page! Bam there’s another! Needless to say my client was a very happy camper too… he even noticed a 300% increase in sales within the first 2 weeks because customers were now utilizing the faster site (amazingly enough, he was getting $1000’s in sales prior to the move even with his old site being slow, now that’s customer commitment).

I was happy, my client was happy, his clients were happy; we were all happy what could be better!  And then it happened, almost 1 month in to its new home on SiteGround.com… A Fatal Error!

Magento Shopping Cart Issue's Fix

My Magento Error… Where my products should be!!

Magento Fatal Error (Allowed memory size)

Assuming that my Magento Shopping Cart issues were now behind me, I began planning the transfer of more sites over to the new hosting platform.  I get a call from my client telling me that the site is down, so I go check it out.

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 89 bytes) in home/xxxxxx/public_html/lib/Varien/Object.php on line 270

I contacted www.siteground.com and notified them of the error and the issue was fixed immediately.  “Nice” I thought that was easy.  Then the next day much to my surprise the error was back again.  I contacted www.siteground.com once again and they told me there wasn’t much they can do as my Magento Shopping Cart was taking up too much of the allocated memory within the shared hosting plan.   They told me my best bet was to upgrade to a VPS package starting at $69 per month, as that package should have enough memory allocation that this issue would go away.

This really annoyed me at the time because before I had purchased the hosting package and moved the website over to www.siteground.com I specifically called them a couple of times to confirm a few things before I had made the move. I was sure to tell them about my current issues with the site, and we spoke about all the things I needed in a new hosting provider. I even went so far to tell them how large my database was, how many products my client had, how many customers were managed, how much traffic was currently being visited every month, as well as any other little detail I could think of at the time.  They assured me “No Problem” their servers were specifically designed to handle all of my issues I had mentioned and all for the low price of $3 per month.

But now they are trying to upsell me from $3 to $69.  Where was this great support I had seen in the beginning, they made no attempt from what I could see to help correct this issue, except to tell me to upgrade to a bigger plan, as that would fix my problem? I was clearly frustrated with their short answers and their lack of commitment to help me and the website I had just transferred over.

Well at this point of the game I turned to Google, my savor as per usual.

Magento Shopping Cart Fatal Error Fixes

I knew exactly what the issue was; however being a shared hosting client my options were limited.  When you get a “Fatal error: Allowed memory size exhausted” notice in your Magento Shopping Cart that usually means one thing.  You need to up the php_value of your memory_limit. Now there are a couple of ways you can do this if you have the proper access (some shared hosting providers allow you to edit these settings, and some others do not, SiteGround.com unfortunately does not).

First you need to check and adjust your php_value memory_limit.  Magento requires a minimum memory value limit of 256M to run properly, but ideally you should have it running at 512M.  The next thing you want to check and adjust if necessary is your php_value max_execution_time.  You want to make sure that this is set to a minimum value of 18000.

## adjust memory limit
php_value memory_limit 256M
php_value max_execution_time 18000

How to Check PHP_Values on a Website

Checking PHP Values within a Magento Website

  1. Login via FTP to the Magento Shopping Cart root directory
  2. Locate the file php.ini.sample.php
  3. Change php.ini.sample.php to phpinfo.php
  4. Go to www.yourwebsite.com/phpinfo.php via your browser
  5. Locate memory_limit (use CTRL+F then type memory_limit hit enter for quicker results)
  6. Locate max_execution_time (use CTRL+F type max_execution_time hit enter)

That phpinfo.php file gives you all your php settings provided to you by your hosting provider.  Be sure to change the name back to php.ini.sample.php or better yet delete the phpinfo.php file all together.  You don’t want hackers to be able to view this file, as it gives them the same privy of information about your current PHP values regarding your website.  This can be very dangerous for you!

Checking PHP Values without a Magento Website

If your Magento Shopping Cart doesn’t have the php.ini.sample.php within its root directory, or you want to check your PHP Settings on a hosting account that isn’t Magento based you can easily do so by following these steps below.

  1. Open Notepad
  2. Add this code to the first line   <?php phpinfo(); ?>
  3. Save Notepad file as phpinfo.php
  4. Upload phpinfo.php to your root directory
  5. Go to www.yourwebsite.com/phpinfo.php via your browser
  6. Locate memory_limit (use CTRL+F then type memory_limit hit enter for quicker results)
  7. Locate max_execution_time (use CTRL+F type max_execution_time hit enter)

Remember to delete this file after you are finished with it.  DO NOT leave this file in your root directory for any reason!

Magento Shopping Cart Fatal Error Solutions

Now that we know that we need to change your settings there are a couple of ways of doing it.

  1. Edit your .htaccess file
  2. Edit your php.ini file

Your hosting provider must grant you permission for you to adjust these settings on your own, or else they will not work.  How do you know if your hosting provider allows for you to adjust these settings on your own?  Well the best way to find out is to contact them and ask? The second way is to adjust the settings within one of the two files above and to check your phpinfo.php file to see if the settings changed at all.  If they haven’t changed once you’ve edited the .htaccess file or the php.ini file then you know for sure that doing those edits has been restricted by your provider.

Magento Fatal Error .htaccess fix

In your Magento Shopping Cart root directory (where you uploaded the phpinfo.php file) you should have a file already in there called .htaccess.  If not find the file called .htaccess.sample, download it to your computer and open it.

NOTE* Opening an .htaccess file can be tricky, if you don’t have the proper software simply change the name of .htaccess to htaccess.txt (removing the (.) period at the front and adding (.txt) at the end) this will allow you to open it in Notepad.  Before you upload it, just rename it back to its original name (.htaccess).

Once you have opened the .htaccess file scroll down to “Adjust Memory Limit” it should look like something below… (Keep in mind anything starting with # means it’s inactive.)

## adjust memory limit
#   php_value memory_limit 64M
php_value memory_limit 128M
php_value max_execution_time 18000

These were the default settings for www.siteground.com, so I made the adjustments as such…

## adjust memory limit
#    php_value memory_limit 64M
php_value memory_limit 256M
php_value max_execution_time 18000

Once you have edited the file, save it and re-upload it and check it through the phpinfo.php file.  See if any changes have taken effect, as well hit refresh on your website, see if the error code went away.  Unfortunately for me they did not, I was unable to make adjustments via my .htaccess file.

Magento Fatal Error php.ini fix

The next thing I did was take the php.ini.sample file and downloaded it to my computer.  I then opened it and searched for “adjust memory limit” once again.

; This file is for CGI/FastCGI installations.
; Try copying it to php5.ini, if it doesn’t work
; adjust memory limit
memory_limit = 64M
max_execution_time = 18000

Making the same edits as I did in the .htaccess file I did the following changes as such…

; adjust memory limit
memory_limit = 256M
max_execution_time = 18000

Once again checking it online to see if it made a difference both by refreshing my website to see if the error code went away and secondly by checking the phpinfo.php file…  Unfortunately, I was at a loss, as I wasn’t able to successfully remove the error code.  My memory limit was still exhausted; the amazing $3 hosting plan just wasn’t big enough for my 5000 products and daily traffic combined.

After taking a small break for about an hour to regroup I decided to take a different approach.  Since I wanted to stay with the $3 hosting plan (as did my client)… other than the memory exhaust issue, it was running fast, with no other hiccups (well at least it was before this issue arose.).  I just couldn’t adjust the settings I needed to because of the shared hosting status of the $3 plan, so I decided to focus on what I could change which was the settings in my backend administration area.

Magento Fatal Error the Final Solution – Victory is Mine!

After doing a little more research I began playing with the backend settings and then finally just like that the error went away and the site was running perfectly, oh what a day!  This is what I did to make it happen (the 1st two steps most Magento users are already pretty familiar with).

Login as Admin and then…

Step 1: Enable all Cache Types

  • Navigate to System> Cache Management and Enable All Cache Types and/or refresh if already enabled.
Frequent Cache Management is Required.

Refresh and Enable All Cache Types.

Step 2: Re-Index all Data

  • Navigate to System> Index Management > then “Select All” and click on Submit. Make sure that Actions is set to Reindex Data not Change Index Mode.
The magento shopping cart sometimes requires index management to be run.

Magento Index Management Window.

Step 3: Enable JavaScript File Merging

  • Navigate to System> Configuration> Developer> JavaScript Settings and select “Yes” to Merge JavaScript Files, then save by clicking “Save Config” (Top right hand corner).

(This step combines all JavaScript files in your Magento system into one file base reducing the large number of HTTP requests the Magento Shopping Cart system makes to the server.  In turn giving you more speed via the more compact file.

Step 4: Combining your CSS Files

  • Navigate to System> Configuration> Developer> CSS Settings and select “Yes” to Merge CSS Files just as you did with the JavaScript files. “Save Config” to save your settings.

Step 5: Turn Off Logs

  • Navigate to System> Configuration> Developer> Log Settings and select “No” under Enabled.
  • Clear the Cache via Cache Management so setting take immediate affect.
Magento Shopping Cart Solutions

You will find Step3, Step4 and Step5 onto of each other.

Step 6: Enable Compilation

  • Navigate to System> Tools> Compilation and select “Run Compilation Process” this is a great tool to speed up your Magento Installation.
  • Clear the Cache via Cache Management so setting take immediate affect.
don't forget to clear magento cache system

Clear the Cache via Cache Management so setting take immediate affect.

Step 7: Uninstall Unused Extensions

  • Navigate to System > Magento Connect > Magento Connect Manager
  • Login
  • Through this window remove any extensions you are not currently using.
  • Clear the Cache via Cache Management so setting take immediate affect.

Step 8: Disable Modules Output

  • Navigate to System> Configuration> Advanced> Advanced
  • These are all the Modules that are currently running on your Shopping Cart.  Anything that is Enabled is currently active on your site.  You want to “Disable” any Modules that you don’t actively use.  For example if you are not using Google Checkout, Moneybookers or PayPal UK as a payment gateway then “Disable” them.  If you don’t have downloadable products for sale then “Disable Mage_Downloadable” , if you turned off your Customer Wishlists, Product Ratings, and Polls then “Disable” them here.
  • Magento Shopping Cart Extensions Management

    Disabling Modules here will greatly improve your speed and help with any would be errors.

    – it was using this feature that ended up saving my site and allowing me to keep the $3 hosting plan.

  • Clear the Cache via Cache Management so setting take immediate affect.

Next Login to CPanel…

If Mod_Deflate is installed on your hosting account you will then see an icon called Optimize Website under the Software/Services section once you’ve logged in.

Optimize Website with Cpanel.

You will see the Optimize Website Icon only if Mod Deflate is installed on your Server.

Step 9: Optimize Website with CPanel

  • Click on Optimize Website
  • Select Compress All Content> Update Settings
Magento Shopping Cart System Website Optimization.

Select Compress All Content.

Tweak .htaccess File

  • Open Your .htaccess File Again… This time we are going to Enable Compression and Disable ETags.

Enable Compression

  • Activate Apache the “mod_deflate” Module.  Mod_deflate will compress content before it allows the visitor browser to grab it such as text, css files, and javascipt code resulting in a smaller download size, making your site faster over all.  To activate “mod_deflate” uncomment the lines so that your .htaccess file looks like the following…

<IfModule mod_deflate.c>

## enable apache served files compression
## http://developer.yahoo.com/performance/rules.html#gzip
# Insert filter on all content
SetOutputFilter DEFLATE
# Insert filter on selected content types only
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css   text/javascript application/javascript
# Netscape 4.x has some problems…
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don’t compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don’t deliver the wrong content
Header append Vary User-Agent env=!dont-vary

The original .htaccess file will look like this…

Magento Mod Deflate Module

The Magento .htaccess file will look like this by default you must uncomment the lines…

Magento Shopping Cart Mod Deflate

…as such to optimize your sites speed and performance.


Disable ETags

  • Etags validate cached components which can slow down a site so it is best to just turn them off as shown below.

## If running in cluster environment, uncomment this
## http://developer.yahoo.com/performance/rules.html#etags

FileETag none

Magento's htaccess file

Remove the # sign to “Uncomment a Line”

Once you have made your edits re-upload your .htaccess file and check to see if your speed has improved. There are  few more things you can do to still improve speed on your Magento Shopping Cart such as install some Magento Plugins that specifically target this issue.  As well as make a few more minor edits to your .htaccess file and admin backend.  After completing all of the above the current Magento Shopping Cart I was referring to in this article has been running perfectly now for about 4 months without any further issues while still using www.siteground.com as the hosting company, with the $3.00 plan still in use.

The minimum required memory limit as we all know to run a Magento Shopping cart is 256M, but on the $3 hosting plan with SiteGround.com they run the memory limit at 128M (which was the cause of my initial issue).  However even with such a low memory limit after utilizing all the fixes mentioned in this article I was able to have my site run perfectly and was able to keep my low cost hosting plan active.  I hope that this article helps you speed up your Magento Shopping Cart.  If you have any questions please do let me know.

Magento Shopping Cart Recap

A good way to test your website speed is by going to http://tools.pingdom.com and run a speed test.  I would recommend that you test your website before and after you make your modifications to see how big a difference it does make.  Remember too if you are new to Magento that you need to Clear you Cache in your Cache Management section when you edit changes to your Magento website, either in FTP or in the Admin backend area.  It’s always best to complete a few changes at a time and then refresh your website to make sure you aren’t causing more errors, there’s nothing worse then spending time on fixing an issue only to find out that you created a new error somehow and now have to back track to figure out what changed caused your new problem.

Share this article

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Category: Magento, Reviews, Tutorials, Web Tools

Leave a Reply

Your email address will not be published. Required fields are marked *