Search This Blog

Tuesday, May 15, 2012

Magento Performance and caching issues or Caching in magento or magento caching techniques

Caching in magento
Magento Performance and caching issues....

MySQL comes with a query cache, which can save the result of SELECT queries for short periods of time – that is, until some change is made to the database. How much benefit you get from the query cache depends strongly on the kind of application you use – this is why the query cache is not turned on by default. When it comes to Magento, tests have shown again and again just how much extra scalability you get if it is enabled. To enable query caching, go to your my.cnf and set the following options in the [mysqld] section: query_cache_type=1 query_cache_size=64M Save your changes and restart the MySQL server – getting a third more requests per second is not uncommon after the change!


----------------------------------------------------------------------
Enable Expires Headers Browsers use caching extensively, and can save a lot of the elements included in a web site locally so that they can be served from the browser’s cache rather than the web server on the next request. This can help quite a bit in shortening load times. The problem is for the browser to know when a file can be served from the cache, and when not – because the local copy is outdated. To solve this issue, browsers rely on two HTTP headers, Expires and Cache-Control. Magento’s default .htaccess file already configures these according to Yahoo’s performance recommendations (more on them below), but does not enable them by default. To enable them, all you need to do is add the following lines to your Apache server configuration (usually found in /etc/apache2/apache.conf): <IfModule mod_expires.c> ExpiresActive On </IfModule> If you don’t have access to the server configuration, you can also add those lines to Magento’s .htaccess file – but then you need to be careful when updating Magento that your changes do not get lost.



---------------------------------------------------------------------------
Enable Block Caching where it makes sense Out of the box, Magento can cache the Block output of your pages. When the next user requests the same block, the output that was previously calculated can be returned directly – without going through all the database queries and model calls again. This is really helpful for parts of pages that don’t change too often but are somewhat expensive to calculate – such as category pages. Clearly, it makes a lot more sense to calculate output once and then cache it for, say, five minutes, than to continuously go through the same model calls with the same results again and again.

---------------------------------------------------------------------------
Make fewer HTTP Requests in your Theme As YSlow alerts you, having many HTTP requests to load a single web page is a performance killer. Even if you enable keep-alive or use a content delivery network, it is still much slower to load many small images than a single bigger file that contains all images. Reducing the number of HTTP requests is largely a performance measure, but also helps scalability a bit.
Using image sprites, you can put all the icons, buttons etc. that you have in your theme into one file that can be downloaded quickly and then just show parts of this large image where you need it. All this involves is a little bit of CSS wizardry. A List Apart has a nice tutorial to get you started at http://www.alistapart.com/articles/sprites/.

-------------------------------------------------------------------------------

Use FastCGI to run PHP If you are using Apache as your web server, there are two ways you can sensibly set up PHP. The first way is to use the mod_php module, which is easiest to use and hence the default with many hosting providers. In this case, a PHP interpreter is run with each process of the web server and on stand-by until a script is executed. If you are wondering why your Apache needs a lot of memory, probably the fact that you are using mod_php is a big part of the answer. On a large site, there may well be hundreds of Apache processes running, and each has its own PHP interpreter. However, only very few of them – often less than one in ten – actually need to run PHP. The rest serve static files or simply wait for new requests. Because PHP uses a lot of memory, it is a good idea to see if you can avoid the overhead generated by having dozens and dozens idle PHP processes running.

The way to avoid the overhead is to use FastCGI instead of mod_php. With FastCGI, a separate internal daemon is run on your web server that is contacted by the web server only when execution of PHP required. Thus you do not need to carry the PHP baggage for all requests.
Setting up FastCGI requires you to make some changes to your server configuration, but the benefits will be large. A good starting point is this article: http://2bits.com/articles/apache-fcgid-acceptable-performance-and-better-resource-utilization.html. For more details, check the Apache web site and the documentation of your distribution.


-------------------------------------------------------------------------------
Use a Content Delivery Network Another way to relieve stress from your servers is to get an external party to serve static files for you. These services, called Content Delivery Networks (CDNs), are getting very popular and prices have fallen a lot over the last year or so. A CDN can really improve the user experience on your site, and is another way around the problems created by mod_php.
Setting up a CDN is quite easy with the free One Pica CDN extension from Magento Connect.

------------------------------------------------------------------------------------

Going Further
You have followed all the steps of this guide, and still your Magento does not scale to the level you need or give you the performance you crave? First, check again if you have really implemented all the steps. The configuration I described above is known to work very well with large Magento stores, serving hundreds of thousands of page impressions per day. Check that your hardware works well and that you are not limited by the bandwidth of your server.

If your site is truly huge, you will want to move to a cluster infrastructure that also provides high availability to insure you against software or hardware failures. You need to set up MySQL replication for your database and balance load between web servers. In practice, this will usually mean that you move to a specialised managed infrastructure provider or get outside consultants to set up the infrastructure for you.

Magento is very well suited for such deployments. You can set different database connections for read and write queries, which is important when you use MySQL replication, use memcache as a distributed cache backend, and the like. So Magento will not limit you there – the problems you may encounter will be related to the operating system and other software stack.

-----------------------------------------------------------------------------------------


How To Check If Query Caching Is Enabled
To check if your host has query caching enabled in the MySQL server, you can issue the following command from your MySQL command prompt:

mysql> SHOW VARIABLES LIKE 'have_query_cache';
+------------------+-------+
| Variable_name | Value    |
+------------------+-------+
| have_query_cache | YES   |
+------------------+-------+


----------------------------------------------------------------------------------------


To verify that query cache is actually operational, you can issue the following command to the MySQL server:

mysql> SHOW VARIABLES LIKE 'query_cache_size';
+------------------+----------+
| Variable_name | Value       |
+------------------+----------+
| query_cache_size | 67108864 |
+------------------+----------+

This shows that we have 64 MB available to our query cache size, a very respectable amount of memory.

The following demonstrates a server that has MySQL query cache disabled by setting the value to zero:

mysql> SHOW VARIABLES LIKE 'query_cache_size';
+------------------+-------+
| Variable_name | Value    |
+------------------+-------+
| query_cache_size | 0     |
+------------------+-------+

------------------------------------------------------------------------------------



Monday, May 14, 2012

Magento Multi site tips.....

Magento Multi site tips.....
1. One of Magento’s most superior strengths are its capabilities for scaling to support multi-store and multi-language retailing all from the same backend. In this tutorial, we will be showing you how to take advantage of Magento’s scalability by creating multiple websites with unique domain names sharing the same product catalog. (***NOTE: Each store can also be configured to offer a unique product catalog as well.)

2. These categories (Clothing, Electronics) should be set as both “Is Active” from the General Information tab and “Is Anchor” from the Display Settings tab for them to appear on the frontend of your Magento shop. (***NOTE: If the websites will not be sharing the same catalog, a Root Category must be created for each website. Thus, if there are 3 websites, there will be 3 Root Categories with subcategories under them.)

Tuesday, May 8, 2012

Facebook PHP login logout working code

define('FACEBOOK_APP_ID', '***YOUR FACEBOOK APPLICATION ID HERE***');
define('FACEBOOK_SECRET', '***YOUR FACEBOOK SECRET APPS KEY HERE***');
function get_facebook_cookie($app_id, $application_secret) {
  $args = array();
  parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
  ksort($args);
  $payload = '';
  foreach ($args as $key => $value) {
    if ($key != 'sig') {
      $payload .= $key . '=' . $value;
    }
  }
  if (md5($payload . $application_secret) != $args['sig']) {
    return null;
  }
  return $args;
}
$cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET);
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:fb="http://www.facebook.com/2008/fbml">
<body>
<?php if ($cookie) {
//cookie is set, user is logged in
$user = json_decode(file_get_contents('https://graph.facebook.com/'.$cookie['uid']));
//Display the facebook user ID, name, gender and Facebook URL in the web browser
echo '<br />';
echo 'Your Facebook ID: '.$user->{'id'};
echo '<br />';
echo 'Your name: '.$user->{'name'};
echo '<br />';
echo 'Your gender: '.$user->{'gender'};
echo '<br />';
echo 'Your Facebook URL: '.$user->{'link'};
echo '<br />';
echo '<fb:login-button autologoutlink="true"></fb:login-button>';
}
else
{
//user is not logged in, display the Facebook login button
echo '<h2>Facebook Application Test page</h2>';
echo '<br />';
echo 'This is the most basic Facebook application PHP source code that will grab the user Facebook full name, gender and Facebook URL.';
echo '<br />Then displays those information in the web browser once the user has successfully logged in';
echo '<br /><br />';
echo '<fb:login-button autologoutlink="true"></fb:login-button>';
}
?>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({appId: '<?= FACEBOOK_APP_ID ?>', status: true,
cookie: true, xfbml: true});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
</script>
</body>
</html>

Monday, May 7, 2012

Magento Developer Certification

Few days ago Magento announced their plans for Magento certification program. As they stated, initial round of certification will be a Beta exam, held on Innovate Developer Conference in San Francisco, October 12 and 13! Those who pass the exam based on the Beta exam analysis, will actually earn the official Magento Developer certification. Final reward for those who pass the exam? They will receive Magento certificate and be able to use the official logo with their name and title. Clearly there is more to it than just a piece of paper, so let me share my thoughts and views with you.

The thing about the certification is that it’s not only about the piece of paper or a card issued by some authority verifying your knowledge and expertise. If you look at it more deeply, additional value lies in the individuals desire to actually go trough it. This shows determination and love towards an area of interest. It’s hard to imagine someone would go trough all the hassle of certification as specific as this one if he does not love his work. This goes for certification in general, not just Magento. This is something hiring managers will know how to recognise and value.

From a personal point of view, as a developer you gain recognition of your Magento skills. Which is not to be ignored, as Magento still is one of the most robust eCommerce platforms our there. This can help differentiate yourself from the competition, possibly increase your value on the market. Not to mention there is a good chance you gain some additional knowledge through preparation and training. Face it as much as you know Magento chances are you skipped a “chapter or two” in your everyday real job (I know I did).

On a company level, there is also a bonus of having some or all of your developers certified. This usually goes in favour of your overall quality.

I’m sure most of you in Magento business will agree that Magento certification was more than welcome and I would even say needed. With all their great products and services now available time is right for quality certification program. I’m only hoping that over the next few months, year or two, most of us in everyday Magento development will earn ourselves a certificate :)

So what’s it all about? Magento Developer Certification landing page has a nice little PDF file called Certified Developer Exam: Self Assessment Checklist. It outlines the certification program which comprises of two levels:

    Magento Certified Developer (MCD)
    Magento Certified Developer Plus (MCD Plus), has an additional 20 questions

Questions are based on Magento Community Edition Magento Enterprise Edition. Surprisingly there is a detailed outline of 10 specific areas that exam covers, all you need to do is to study it.

    Basics (5%)
    Request Flow (7%)
    Rendering (8%)
    Working with Database in Magento (12%)
    Entity-Attribute-Value (EAV) Model (10%)
    Adminhtml (8%)
    Catalog (10%)
    Checkout (15%)
    Sales and Customers (12%)
    Advanced features (13%)

Check the document for details.

In a nutshell that’s it for now. Grab your Magento installations, some coffee, and run trough outlined exam areas if you are interested in taking exam. I must say, it does not look like it’s going to be easy. Regardless of your experience, Magento is still a large platform, meaning lot of terrain to cover so get prepared:)

Cheers.

Source http://inchoo.net/ecommerce/magento/magento-certification-why-bother/

More links and study guide

http://www.magentocommerce.com/blog/magento-developer-certification-how-do-i-know-if-im-ready/
 

Friday, May 4, 2012

Grouped Vs Bundle Products

Grouped Products

A grouped product is essentially a selection of simple products displayed equally on the product page, each with quantity boxes so the user can decide how many of each they want before they add to cart.The products displayed are normally of a similar nature (e.g. a plate and a saucer)

Examples
  
  • Tablewewar Set - Imagine a product called ‘tablewear set’, and you can decide how many plates, dishes, cups and saucers you want to buy as part of the set.
  • Box of Pens – Similar to the tablewear set, another example of a grouped product may be for purchasing pens for a company. A grouped product is great for when you need to buy in bulk. The product may be Biro pens, and you can decide how many of your biro pens are red, blue, green and black.
  • Set of Knives – This is an example used on Magento’s own website and nicely demonstrates a grouped product in all its glory. You can purchase a set of Chef’s knives and you can decide how many of each size you want in the set.
 

Bundle Products

A bundle product should viewed as a product you get to customise to your requirements. You choose what goes with it and how high/low spec you want it to be. This gives customers the freedom to pretty much ‘build’ their ideal product. The products displayed are normally not very similar (e.g. a hard drive and a mouse mat).
 
Examples
  •     Tennis Racket – The name and make of the tennis racket is the bundle product, but you have to build your racket as a bundle. So you choose the grip size, followed by the strings you want. A nice custom option box could be thrown in to determine the tension of the strings. You can also throw in a racket bag and extra grips if you wish.
  •     Build your Computer – This is the most famous bundle product on Magento’s Demo Store. When you build your computer you can customise everything including what size processor you want, which monitor you want, the inclusion of extra graphics card etc, until you have

 

Monday, April 30, 2012

Magento admin grid add from and to search in admin grid

Magento admin grid add from and to search in admin grid

$this->addColumn("designer_id", array(
                "header" => Mage::helper("Module")->__("User ID"),
                "align" =>"right",
                "width" => "50px",
                'type'  => 'currency',
                "index" => "user_id",
                ));

                'type'  => 'currency', is used to search for integer or decimal type

$this->addColumn("created_date", array(
                "header" => Mage::helper("Module")->__("Modified Date"),
                "align" =>"center",
                "width" => "100px",
                'type' => 'datetime',
                "index" => "mod_date",
                ));

                'type' => 'datetime', is ued to seach date time range

Thursday, April 26, 2012

Magento admin grid mass delete, mass status change checkbox option

Magento admin grid mass delete, mass status change checkbox option

In your Grid.php add
protected function _prepareMassaction()
    {
        $this->setMassactionIdField('Module_id');
        $this->getMassactionBlock()->setFormFieldName('banners');

        $this->getMassactionBlock()->addItem('delete', array(
             'label'    => Mage::helper('Module')->__('Delete'),
             'url'      => $this->getUrl('*/*/massDelete'),
             'confirm'  => Mage::helper('Module')->__('Are you sure?')
        ));

        $statuses = Mage::getSingleton('Module/status')->getOptionArray();

        array_unshift($statuses, array('label'=>'', 'value'=>''));
        $this->getMassactionBlock()->addItem('status', array(
             'label'=> Mage::helper('Module')->__('Change status'),
             'url'  => $this->getUrl('*/*/massStatus', array('_current'=>true)),
             'additional' => array(
                    'visibility' => array(
                         'name' => 'status',
                         'type' => 'select',
                         'class' => 'required-entry',
                         'label' => Mage::helper('Module')->__('Status'),
                         'values' => $statuses
                     )
             )
        ));
        return $this;
    }
-----------------------------------------------------------
in your adminhtml-> XXXcontroller .php file
 public function massDeleteAction() {
        $ids = $this->getRequest()->getParam('Module');
        if(!is_array($ids)) {
            Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select Banner(s)'));
        } else {
            try {
                foreach ($ids as $id) {
                    $banners = Mage::getModel('Module/Module')->load($id);
                    $banners->delete();
                }
                Mage::getSingleton('adminhtml/session')->addSuccess(
                    Mage::helper('adminhtml')->__(
                        'Total of %d record(s) were successfully deleted', count($ids)
                    )
                );
            } catch (Exception $e) {
                Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
            }
        }
        $this->_redirect('*/*/index');
    }
   
    public function massStatusAction()
    {
        $bannersIds = $this->getRequest()->getParam('module');
        if(!is_array($ids)) {
            Mage::getSingleton('adminhtml/session')->addError($this->__('Please select Banner(s)'));
        } else {
            try {
                foreach ($ids as $id) {
                    $banners = Mage::getSingleton('Module/Module')
                        ->load($id)
                        ->setStatus($this->getRequest()->getParam('status'))
                        ->setIsMassupdate(true)
                        ->save();
                }
                $this->_getSession()->addSuccess(
                    $this->__('Total of %d record(s) were successfully updated', count($ids))
                );
            } catch (Exception $e) {
                $this->_getSession()->addError($e->getMessage());
            }
        }
        $this->_redirect('*/*/index');
    }