Boost magento performances managing the two level cache

MagentoIf you are after some improvements on magento “speed”, you will probably interested in why it is so slow, a great explanation about why (a piece at least) magento is slow, is detailed here.

To sum it up, assuming you are using memcached to store the sessions (and I hope you do), here a small snippet to be applied to your app/etc/local.xml file to handle that second level cache:


As it is in the snippet, the second level is stored in the database instead of writing everything in the files as it does by default, using this (after restarting memcached) you will notice a huge boost in speed, you can also disable it by setting the slow_backend_store_data to 0, but that will slow down a lot the website when the cache is empty.



Magento Dataflow profiles with over 8k products

MagentoIf you are trying to export products from Magento’s Dataflow profile, and you have more than 8000 products, it is common to end up with an error 500 without many information.

To be able to handle that from the web interface without running a profile from the shell, you have to tell your fcgi to be patient!

Here is how to do so:

FcgidBusyTimeout 3600
FcgidIdleTimeout 3600
FcgidProcessLifeTime 7200

Here some more specific informations.


Export a profile from shell

MagentoI was struggling to run an export profile from the web interface of Magento without having any luck, increasing timeout or memory or anything was not helping at all.
Since I needed that export to be done, with this small script you can do that:

$profileId = 7; #The ID of the profile from the administration view
require_once 'app/Mage.php';
$profile = Mage::getModel('dataflow/profile');
$userModel = Mage::getModel('admin/user');
if (!$profile->getId()) {
Mage::getSingleton('adminhtml/session')->addError('[ERROR] Invalid ID');
Mage::register('current_convert_profile', $profile);


Modify the password via usermod -p

Since I wasted too much time behind this, here is how to do it in 2 steps:

1. Retrieve the crypted password

openssl passwd Your_Password

2. Copy and paste the output to your usermod call

usermod -p openssl_output user_name


Call a custom template file into a CMS page

MagentoI had to create a customized search box and display it on the homepage, generated as CMS page with some features.
To do so, here a small command:

{{block type="core/template" template="path/filename.phtml"}}

Where the path to the file is on the current theme directory.


Delete all products in a given category via php

MagentoI had to remove all the products assigned to a category that was used as trash bin for some reasons, the problem was that the amount of products was pretty massive (16000) and I had no chances to do it manually, so I made a small PHP script to do the job.

 require_once "app/Mage.php";
 $category_id = 146;
 $products = Mage::getModel('catalog/product')->getCollection();
 foreach($products as $product){
  $categories = $product->getCategoryIds();
  if(in_array($category_id, $categories)) {
   $product_load = Mage::getSingleton('catalog/product')->load($product->getId());
   Mage::dispatchEvent('catalog_controller_product_delete', array('product' => $product_load));


Running magento without .htaccess

MagentoIf you are optimizing a Magento vhost, you probably disabled the .htaccess necessities as they slow down by a nice amount.
Doing so however, lead to the following error:

Your web server is configured incorrectly. As a result, configuration files with sensitive information are accessible from the outside. Please contact your hosting provider.

That means that the files local.xml and config.xml are accessible from the user’s browser, to fix that you need to set the correct permissions for those 2 files, that is 500.