Clear log table & speedup the website speed as well as free up the server space

Magento keep the log file internally to track the visitor, cart, customer, report etc. Once the website get older the logs get larger and that make slow down the website speed and consume the server space

In this article i will guide you how to prevent large log data. That will be beneficial for your website speed and server space

There is two way to achieve the target:
1) Manual process: Go to the database and truncate the below tables time to time:

2) Clear the log table using cronjobs: This process is safe and easy to implement. Create a php script, using mysql query truncate data from database table.add This php script at cronjob as per as your requirement.
$query1 = “truncate table dataflow_batch_export”;
$query2 = “truncate table dataflow_batch_import”;
$query3 = “truncate table log_customer”;
$query = “truncate table log_quote”;
$query4 = “truncate table log_summary”;
$query5 = “truncate table log_summary_type”;
$query6 = “truncate table log_url”;
$query7 = “truncate table log_url_info”;
$query8 = “truncate table log_visitor”;
$query9 = “truncate table log_visitor_info”;
$query10 = “truncate table log_visitor_online”;
$query11 = “truncate table report_viewed_product_index”;
$query12 = “truncate table report_compared_product_index”;
$query13 = “truncate table report_event”;

Add the php script in cronjob after 15-30 days. so the log file will clear time to time and website speed didn’t get slow down, also it save your server space.

Reindex magento data via SSH

The fastest way to re-index magento data is manually via SSH.
When you re-index from admin section, sometime the re-indexing process get stuck due to expire session or crss maximum execution time or any other reason. The best and fastest way to re-indexing the Magento data is via SSH

In this article i will guide you how to re-index via SSH:

  • Login to your SSH account. if you didn’t have please contact with the server guy, they will provide you.
  • Go to the server directory where magento get installed
  • Got to the “shell” directory. cd your_magento_directory/shell
  • now you can use below code to re-index magento data:
    php -f indexer.php — -reindex catalog_product_attribute
    php -f indexer.php — -reindex catalog_product_price
    php -f indexer.php — -reindex catalog_url
    php -f indexer.php — -reindex catalog_product_flat
    php -f indexer.php — -reindex catalog_category_flat
    php -f indexer.php — -reindex catalog_category_product
    php -f indexer.php — -reindex catalogsearch_fulltext
    php -f indexer.php — -reindex cataloginventory_stock
  • if you want to re-index all then use:
    php -f indexer.php reindexall

Session Management In magento1

In this blog i will explain you how to set, retrieve and unset session variable in Magento.
Before start i would like to inform you, By default Magento equipped with three type of session:

  • Core Session
  • Customer Session
  • Checkout Session

Core Session

Core sessions are bone of Magento, you can use it anywhere any place in the code.
Set core session: Mage::getSingelton(‘core/session’)->set();
This will set the value (value_of_session) in session variable name (your_session_name).
$myValue =’test’;
In the above example i have set the value “test” in variable myValue, and set myValue in session. Now the session “MyValue” set with value “test”.
Retrieve core session value: Mage::getSingelton(‘core/session’)->get();,
This will return the session variable value which you set in “your_session_name”.
Unset core session:Mage::getSingleton(‘core/session’)->uns();, This will delete session value which you set in ““.

Same with the customer and checkout session:

Magento : Get Base Url , Skin Url , Media Url , Js Url , Store Url and Current Url

Get Url in phtml files

  • Get Base Url : Mage::getBaseUrl();
  • Get Skin Url : Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);
  • Unsecure Skin Url : $this->getSkinUrl(‘images/imagename.jpg’);
  • Secure Skin Url : $this->getSkinUrl(‘images/imagename.gif’, array(‘_secure’=>true));
  • Get Media Url : Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
  • Get Js Url : Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);
  • Get Store Url : Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
  • Get Current Url Mage::helper(‘core/url’)->getCurrentUrl();

Get Url in cms pages or static blocks

  • Get Base Url : {{store url=””}}
  • Get Skin Url : {{skin url=’images/imagename.jpg’}}
  • Get Media Url : {{media url=’/imagename.jpg’}}
  • Get Store Url : {{store url=’mypage.html’}}