SlideShare a Scribd company logo
1 of 46
Magento Debug Process




Pavel Novitsky


Meet Magento Belarus 2012
Debugging is twice as hard as
writing the code in the first place.

Therefore, if you write the code as
cleverly as possible, you are, by
definition, not smart enough to
debug it.

Brian Kernighan
The main thing about Magento is PHP
Popular practices of PHP applications debugging.




                   1. Error output
                   2. Variable values
                   3. Structured data
                   4. Code tracing
                   5. Objects analysis
                   6. Database query
Popular practices of PHP applications debugging.

Error output
Variable values
Structured data
Code tracing
Objects analysis
Database query



                                  Error output

  Directly in the application:               In php.ini:

  ini_set('display_errors', 'On');           display_errors = On
  error_reporting(E_ALL | E_STRICT);         error_reporting = E_ALL | E_STRICT
Popular practices of PHP applications debugging.

Error output
Variable values
Structured data
Code tracing
Objects analysis
Database query



                            Variable value output


                                    echo $myVar;

                                   Virtually useless.

                      In most cases — a senseless waste of time.
Popular practices of PHP applications debugging.

Error output
Variable values
Structured data
Code tracing
Objects analysis
Database query



                                        Structured data output


  echo '<pre>'.                                     var_dump($myArray);
             print_r($myArray, true).
  '</pre>';



   Array
   (                                                array(2) { ["key1"]=> string(7) "value 1" ["key2"]=>
     [key1] => value 1                              string(7) "value 2" }
     [key2] => value 2
   )
Popular practices of PHP applications debugging.

Error output
Variable values
Structured data
Code tracing
Objects analysis
Database query




                               Code tracing


                   debug_backtrace() and print_debug_backtrace()
Popular practices of PHP applications debugging.

Error output
Variable values
Structured data
Code tracing
Objects analysis
Database query




                    What object do we have?

                             get_class()

                             get_class_vars()

                             get_declared_classes()

                             method_exists()
Popular practices of PHP applications debugging.

Error output
Variable values
Structured data
Code tracing
Objects analysis
Database query




                                Database query


a) echo $sql = "SELECT `some_field1` FROM `table` WHERE `some_field2` = '$var'";


b) $res = mysql_query($sql) or die(mysql_error());
It's good enough for a majority of applications.


          But what about Magento?
Popular practices of PHP applications debugging.




                         Error output

        error_reporting(E_ALL | E_STRICT);
        ini_set('display_errors', 1);



        if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
            Mage::setIsDeveloperMode(true);
        }

        add
        SetEnv MAGE_IS_DEVELOPER_MODE “true”
        to .htaccess
Standard practices used in Magento




                         Variable value output


                    For intermediate variable verification only.

                                   Still useless.
Standard practices used in Magento




                        Structured data output



           $customer = Mage::getModel('customer/customer')->load(1);


           print_r($customer);
Standard practices used in Magento




                                          Structured data output


Mage_Customer_Model_Customer Object ( [_eventPrefix:protected] => customer [_eventObject:protected] => customer [_errors:protected] =>
Array ( ) [_attributes:protected] => [_addresses:protected] => [_addressesCollection:protected] => [_isDeleteable:protected] => 1 [
_isReadonly:protected] => [_resourceName:protected] => customer/customer [_resource:protected] => [_resourceCollectionName:protected] =>
customer/customer_collection [_cacheTag:protected] => [_dataSaveAllowed:protected] => 1 [_isObjectNew:protected] => [_data:protected] =>
Array ( [entity_id] => 1 [entity_type_id] => 1 [attribute_set_id] => 0 [website_id] => 1 [email] => john.doe@example.com [group_id] => 1 [
increment_id] => 000000001 [store_id] => 1 [created_at] => 2007-08-30 23:23:13 [updated_at] => 2008-08-08 12:28:24 [is_active] => 1 [
firstname] => John [lastname] => Doe [password_hash] => 2049484a4020ed15d0e4238db22977d5:eg [prefix] => [middlename] => [suffix] =>
[taxvat] => [default_billing] => 274 [default_shipping] => 274 ) [_hasDataChanges:protected] => [_origData:protected] => Array ( [entity_id] =>
1 [entity_type_id] => 1 [attribute_set_id] => 0 [website_id] => 1 [email] => john.doe@example.com [group_id] => 1 [increment_id] =>
000000001 [store_id] => 1 [created_at] => 2007-08-30 23:23:13 [updated_at] => 2008-08-08 12:28:24 [is_active] => 1 [firstname] => John
[lastname] => Doe [password_hash] => 2049484a4020ed15d0e4238db22977d5:eg [prefix] => [middlename] => [suffix] => [taxvat] => [
default_billing] => 274 [default_shipping] => 274 ) [_idFieldName:protected] => entity_id [_isDeleted:protected] => [_oldFieldsMap:protected] =>
Array ( ) [_syncFieldsMap:protected] => Array ( ) )
Standard practices used in Magento




                               Useless again?
Standard practices used in Magento




                                     Varien_Object::getData()


                                     Varien_Object::debug()
Standard practices used in Magento




                        Structured data output



           $customer = Mage::getModel('customer/customer')->load(1);


           echo '<pre>'.print_r($customer->debug(), true);
Standard practices used in Magento


                       Structured data output
                           [entity_id] => 1
                           [entity_type_id] => 1
                           [attribute_set_id] => 0
                           [website_id] => 1
                           [email] => john.doe@example.com
                           [group_id] => 1
                           [increment_id] => 000000001
                           [store_id] => 1
                           [created_at] => 2007-08-30 23:23:13
                           [updated_at] => 2008-08-08 12:28:24
                           [is_active] => 1
                           [firstname] => John
                           [lastname] => Doe
                           [password_hash] => 2049484a4020ed15d0e4238db22977d5:eg
                           [prefix] =>
                           [middlename] =>
                           [suffix] =>
                           [taxvat] =>
                           [default_billing] => 274
                           [default_shipping] => 274
Standard practices used in Magento




                                 Code tracing


          debug_backtrace()
                                                Varien_Debug::backtrace()
       print_debug_backtrace()
Standard practices used in Magento




                            Object analysis

                               get_class()

                               get_class_vars()

                               get_declared_classes()

                               method_exists()



                           Used everywhere in Magento
Standard practices used in Magento



                          Database queries



                               echo $sql = "SELECT `some_field1` FROM `table`”;


                               $res = mysql_query($sql) or die(mysql_error());
Standard practices used in Magento



                          Database queries


                            Display a query:

                            $myCollection->load(true);



                            Write a query to the system log:

                            $myCollection->load(false, true);
Standard practices used in Magento



                            Database queries

          Mage::getModel('catalog/product')->getCollection()->load(true);




          $model = Mage::getModel('catalog/product')->getCollection();
          $sql = $model->getSelect()->__toString();
          echo $sql;




              SELECT `e`.* FROM `catalog_product_entity` AS `e`
Standard practices used in Magento



                          Database queries

                Write all the queries to var/debug/pdo_mysql.log




                    lib/Varien/Db/Adapter/Pdo/Mysql.php:


                      protected $_debug        = true;
                      protected $_logAllQueries= true;
What else?
Logging
Let’s experiment

<?php

error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);

$mageFilename = 'app/Mage.php';
require_once $mageFilename;

Mage::setIsDeveloperMode(true);
umask(0);

Mage::app();

// … our code …
— developer’s Swiss knife



  DEBUGGING and PROFILING
xDebug


                 Installation
         http://xdebug.org/download.php


                 Setting up
         xdebug.profiler_enable_trigger=on
         xdebug.remote_autostart=off
         xdebug.remote_enable=1
         xdebug.remote_host="127.0.0.1"
         xdebug.remote_port=9000
         xdebug.remote_handler="dbgp"
         xdebug.idekey="netbeans"
         xdebug.collect_vars=on
         xdebug.collect_params=4
         xdebug.show_local_vars=on
         xdebug.var_display_max_depth=5
         xdebug.show_exception_trace=on

         zend_extension=/usr/lib/php5/20090626+lfs/xdebug.so

         ; zend_extension_ts="c:phpextphp_xdebug-2.0.1-5.2.1.dll"
xDebug


         Setting up NetBeans IDE
xDebug


                    Well, what good will that do?
         http://example.com/index.php?XDEBUG_SESSION_START=netbeans
xDebug




         http://example.com/index.php?XDEBUG_SESSION_START=netbeans




                      Xdebug helper http://bit.ly/KuCo2c




                      easy Xdebug http://bit.ly/LKpvjC
xDebug




              Profiling



         xdebug.profiler_enable=1
xDebug — profiling


                             Logs visualization


                     Webgrind               http://bit.ly/LXMGFJ

                     Kcachegrind            http://bit.ly/KGzyAw

                     WinCacheGrind          http://bit.ly/Nh4iPY

                     Xdebugtoolkit          http://bit.ly/LmB4t9

                     MacCallGrind           http://bit.ly/LlerGS

                     CachegrindVisualizer   http://bit.ly/OD6dLy
The client visited…
<disable_local_modules>true</disable_local_modules>
<config>
    <modules>
        <Some_Module>
           <active>false</active>
        <Some_Module>
    </modules>
</config>
Magento Connect — developer tools



         Commerce Bug http://bit.ly/M8ggqh
Magento Connect — developer tools



         Developer Toolbar for Magento http://bit.ly/LnSW8s
Magento Connect — developer tools



         Advanced Developer Tools http://bit.ly/Lo1Vqa




                            Only for versions 1.6.1 and earlier
Magento Connect — developer tools




             Developer Toolbar http://bit.ly/LnD1Hk
Magento Connect — developer tools



                          Magento FirePHP http://bit.ly/LnYGyX

       Mage::helper('firephp')->send('Lorem ipsum sit amet ..');
       Mage::helper('firephp')->debug(Mage::getModel('catalog/product')->load(54));
Magento Connect — developer tools




                 Developer Helper http://bit.ly/OLauwz
THANK YOU FOR YOUR ATTENTION



         pavel@belvg.com

More Related Content

What's hot

Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
references
 
td_mxc_rubyrails_shin
td_mxc_rubyrails_shintd_mxc_rubyrails_shin
td_mxc_rubyrails_shin
tutorialsruby
 
Zf2 how arrays will save your project
Zf2   how arrays will save your projectZf2   how arrays will save your project
Zf2 how arrays will save your project
Michelangelo van Dam
 

What's hot (20)

Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
 
購物車程式架構簡介
購物車程式架構簡介購物車程式架構簡介
購物車程式架構簡介
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
 
Doctrine 2
Doctrine 2Doctrine 2
Doctrine 2
 
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for PerformanceMeet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
 
Caching and Scaling WordPress using Fragment Caching
Caching and Scaling WordPress using Fragment CachingCaching and Scaling WordPress using Fragment Caching
Caching and Scaling WordPress using Fragment Caching
 
Dig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup CairoDig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup Cairo
 
[PHP] Zend_Db (Zend Framework)
[PHP] Zend_Db (Zend Framework)[PHP] Zend_Db (Zend Framework)
[PHP] Zend_Db (Zend Framework)
 
Test driven development_for_php
Test driven development_for_phpTest driven development_for_php
Test driven development_for_php
 
Your code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnConYour code sucks, let's fix it - DPC UnCon
Your code sucks, let's fix it - DPC UnCon
 
Ajax nested form and ajax upload in rails
Ajax nested form and ajax upload in railsAjax nested form and ajax upload in rails
Ajax nested form and ajax upload in rails
 
PHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くためにPHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くために
 
Advanced Django
Advanced DjangoAdvanced Django
Advanced Django
 
Alfredo-PUMEX
Alfredo-PUMEXAlfredo-PUMEX
Alfredo-PUMEX
 
Moodle Quick Forms
Moodle Quick FormsMoodle Quick Forms
Moodle Quick Forms
 
td_mxc_rubyrails_shin
td_mxc_rubyrails_shintd_mxc_rubyrails_shin
td_mxc_rubyrails_shin
 
Zf2 how arrays will save your project
Zf2   how arrays will save your projectZf2   how arrays will save your project
Zf2 how arrays will save your project
 
RicoLiveGrid
RicoLiveGridRicoLiveGrid
RicoLiveGrid
 
Separation of concerns - DPC12
Separation of concerns - DPC12Separation of concerns - DPC12
Separation of concerns - DPC12
 

Viewers also liked (18)

G 8 countries
G 8 countriesG 8 countries
G 8 countries
 
Deemagi Kasrat (Quiz)
Deemagi Kasrat (Quiz)Deemagi Kasrat (Quiz)
Deemagi Kasrat (Quiz)
 
лікування гепатитів на асоціацію
лікування гепатитів на асоціаціюлікування гепатитів на асоціацію
лікування гепатитів на асоціацію
 
хронічний гастрит
хронічний гастритхронічний гастрит
хронічний гастрит
 
War of digital tvs
War of digital tvsWar of digital tvs
War of digital tvs
 
Pancreatitis chronic лiкарi
Pancreatitis chronic лiкарiPancreatitis chronic лiкарi
Pancreatitis chronic лiкарi
 
Виразкова хвороба
Виразкова хворобаВиразкова хвороба
Виразкова хвороба
 
Markets and brokers
Markets and brokersMarkets and brokers
Markets and brokers
 
Meet Magento Belarus debug Pavel Novitsky (rus)
Meet Magento Belarus debug Pavel Novitsky (rus)Meet Magento Belarus debug Pavel Novitsky (rus)
Meet Magento Belarus debug Pavel Novitsky (rus)
 
Quiz on Tourism
Quiz on TourismQuiz on Tourism
Quiz on Tourism
 
Ulcer without films
Ulcer without filmsUlcer without films
Ulcer without films
 
Панкреатит
ПанкреатитПанкреатит
Панкреатит
 
хозл
хозлхозл
хозл
 
бронхіальна астма
бронхіальна астмабронхіальна астма
бронхіальна астма
 
Investment alternatives
Investment alternativesInvestment alternatives
Investment alternatives
 
Ethics
EthicsEthics
Ethics
 
Crisil
CrisilCrisil
Crisil
 
Market selection in international marketing
Market selection in international marketingMarket selection in international marketing
Market selection in international marketing
 

Similar to Meet Magento Belarus debug Pavel Novitsky (eng)

Making Magento flying like a rocket! (A set of valuable tips for developers)
Making Magento flying like a rocket! (A set of valuable tips for developers)Making Magento flying like a rocket! (A set of valuable tips for developers)
Making Magento flying like a rocket! (A set of valuable tips for developers)
Ivan Chepurnyi
 
Php tips-and-tricks4128
Php tips-and-tricks4128Php tips-and-tricks4128
Php tips-and-tricks4128
PrinceGuru MS
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
Michelangelo van Dam
 
Dealing with Legacy PHP Applications
Dealing with Legacy PHP ApplicationsDealing with Legacy PHP Applications
Dealing with Legacy PHP Applications
Clinton Dreisbach
 

Similar to Meet Magento Belarus debug Pavel Novitsky (eng) (20)

Making Magento flying like a rocket! (A set of valuable tips for developers)
Making Magento flying like a rocket! (A set of valuable tips for developers)Making Magento flying like a rocket! (A set of valuable tips for developers)
Making Magento flying like a rocket! (A set of valuable tips for developers)
 
Quality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStormQuality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStorm
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
Modernising Legacy Code
Modernising Legacy CodeModernising Legacy Code
Modernising Legacy Code
 
Growing up with Magento
Growing up with MagentoGrowing up with Magento
Growing up with Magento
 
Magento code audit
Magento code auditMagento code audit
Magento code audit
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
Magento Indexes
Magento IndexesMagento Indexes
Magento Indexes
 
Php tips-and-tricks4128
Php tips-and-tricks4128Php tips-and-tricks4128
Php tips-and-tricks4128
 
PHP security audits
PHP security auditsPHP security audits
PHP security audits
 
Тестирование и Django
Тестирование и DjangoТестирование и Django
Тестирование и Django
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
 
Dealing with Legacy PHP Applications
Dealing with Legacy PHP ApplicationsDealing with Legacy PHP Applications
Dealing with Legacy PHP Applications
 
Utilization of zend an ultimate alternate for intense data processing
Utilization of zend  an ultimate alternate for intense data processingUtilization of zend  an ultimate alternate for intense data processing
Utilization of zend an ultimate alternate for intense data processing
 
PHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4DevelopersPHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4Developers
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2
 
Ch ch-changes cake php2
Ch ch-changes cake php2Ch ch-changes cake php2
Ch ch-changes cake php2
 
PHP tips and tricks
PHP tips and tricks PHP tips and tricks
PHP tips and tricks
 
Introduction to Active Record at MySQL Conference 2007
Introduction to Active Record at MySQL Conference 2007Introduction to Active Record at MySQL Conference 2007
Introduction to Active Record at MySQL Conference 2007
 
Optimization in django orm
Optimization in django ormOptimization in django orm
Optimization in django orm
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Meet Magento Belarus debug Pavel Novitsky (eng)

  • 1. Magento Debug Process Pavel Novitsky Meet Magento Belarus 2012
  • 2. Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. Brian Kernighan
  • 3. The main thing about Magento is PHP
  • 4. Popular practices of PHP applications debugging. 1. Error output 2. Variable values 3. Structured data 4. Code tracing 5. Objects analysis 6. Database query
  • 5. Popular practices of PHP applications debugging. Error output Variable values Structured data Code tracing Objects analysis Database query Error output Directly in the application: In php.ini: ini_set('display_errors', 'On'); display_errors = On error_reporting(E_ALL | E_STRICT); error_reporting = E_ALL | E_STRICT
  • 6. Popular practices of PHP applications debugging. Error output Variable values Structured data Code tracing Objects analysis Database query Variable value output echo $myVar; Virtually useless. In most cases — a senseless waste of time.
  • 7. Popular practices of PHP applications debugging. Error output Variable values Structured data Code tracing Objects analysis Database query Structured data output echo '<pre>'. var_dump($myArray); print_r($myArray, true). '</pre>'; Array ( array(2) { ["key1"]=> string(7) "value 1" ["key2"]=> [key1] => value 1 string(7) "value 2" } [key2] => value 2 )
  • 8. Popular practices of PHP applications debugging. Error output Variable values Structured data Code tracing Objects analysis Database query Code tracing debug_backtrace() and print_debug_backtrace()
  • 9. Popular practices of PHP applications debugging. Error output Variable values Structured data Code tracing Objects analysis Database query What object do we have? get_class() get_class_vars() get_declared_classes() method_exists()
  • 10. Popular practices of PHP applications debugging. Error output Variable values Structured data Code tracing Objects analysis Database query Database query a) echo $sql = "SELECT `some_field1` FROM `table` WHERE `some_field2` = '$var'"; b) $res = mysql_query($sql) or die(mysql_error());
  • 11. It's good enough for a majority of applications. But what about Magento?
  • 12. Popular practices of PHP applications debugging. Error output error_reporting(E_ALL | E_STRICT); ini_set('display_errors', 1); if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) { Mage::setIsDeveloperMode(true); } add SetEnv MAGE_IS_DEVELOPER_MODE “true” to .htaccess
  • 13. Standard practices used in Magento Variable value output For intermediate variable verification only. Still useless.
  • 14. Standard practices used in Magento Structured data output $customer = Mage::getModel('customer/customer')->load(1); print_r($customer);
  • 15. Standard practices used in Magento Structured data output Mage_Customer_Model_Customer Object ( [_eventPrefix:protected] => customer [_eventObject:protected] => customer [_errors:protected] => Array ( ) [_attributes:protected] => [_addresses:protected] => [_addressesCollection:protected] => [_isDeleteable:protected] => 1 [ _isReadonly:protected] => [_resourceName:protected] => customer/customer [_resource:protected] => [_resourceCollectionName:protected] => customer/customer_collection [_cacheTag:protected] => [_dataSaveAllowed:protected] => 1 [_isObjectNew:protected] => [_data:protected] => Array ( [entity_id] => 1 [entity_type_id] => 1 [attribute_set_id] => 0 [website_id] => 1 [email] => john.doe@example.com [group_id] => 1 [ increment_id] => 000000001 [store_id] => 1 [created_at] => 2007-08-30 23:23:13 [updated_at] => 2008-08-08 12:28:24 [is_active] => 1 [ firstname] => John [lastname] => Doe [password_hash] => 2049484a4020ed15d0e4238db22977d5:eg [prefix] => [middlename] => [suffix] => [taxvat] => [default_billing] => 274 [default_shipping] => 274 ) [_hasDataChanges:protected] => [_origData:protected] => Array ( [entity_id] => 1 [entity_type_id] => 1 [attribute_set_id] => 0 [website_id] => 1 [email] => john.doe@example.com [group_id] => 1 [increment_id] => 000000001 [store_id] => 1 [created_at] => 2007-08-30 23:23:13 [updated_at] => 2008-08-08 12:28:24 [is_active] => 1 [firstname] => John [lastname] => Doe [password_hash] => 2049484a4020ed15d0e4238db22977d5:eg [prefix] => [middlename] => [suffix] => [taxvat] => [ default_billing] => 274 [default_shipping] => 274 ) [_idFieldName:protected] => entity_id [_isDeleted:protected] => [_oldFieldsMap:protected] => Array ( ) [_syncFieldsMap:protected] => Array ( ) )
  • 16. Standard practices used in Magento Useless again?
  • 17. Standard practices used in Magento Varien_Object::getData() Varien_Object::debug()
  • 18. Standard practices used in Magento Structured data output $customer = Mage::getModel('customer/customer')->load(1); echo '<pre>'.print_r($customer->debug(), true);
  • 19. Standard practices used in Magento Structured data output [entity_id] => 1 [entity_type_id] => 1 [attribute_set_id] => 0 [website_id] => 1 [email] => john.doe@example.com [group_id] => 1 [increment_id] => 000000001 [store_id] => 1 [created_at] => 2007-08-30 23:23:13 [updated_at] => 2008-08-08 12:28:24 [is_active] => 1 [firstname] => John [lastname] => Doe [password_hash] => 2049484a4020ed15d0e4238db22977d5:eg [prefix] => [middlename] => [suffix] => [taxvat] => [default_billing] => 274 [default_shipping] => 274
  • 20. Standard practices used in Magento Code tracing debug_backtrace() Varien_Debug::backtrace() print_debug_backtrace()
  • 21. Standard practices used in Magento Object analysis get_class() get_class_vars() get_declared_classes() method_exists() Used everywhere in Magento
  • 22. Standard practices used in Magento Database queries echo $sql = "SELECT `some_field1` FROM `table`”; $res = mysql_query($sql) or die(mysql_error());
  • 23. Standard practices used in Magento Database queries Display a query: $myCollection->load(true); Write a query to the system log: $myCollection->load(false, true);
  • 24. Standard practices used in Magento Database queries Mage::getModel('catalog/product')->getCollection()->load(true); $model = Mage::getModel('catalog/product')->getCollection(); $sql = $model->getSelect()->__toString(); echo $sql; SELECT `e`.* FROM `catalog_product_entity` AS `e`
  • 25. Standard practices used in Magento Database queries Write all the queries to var/debug/pdo_mysql.log lib/Varien/Db/Adapter/Pdo/Mysql.php: protected $_debug = true; protected $_logAllQueries= true;
  • 28. Let’s experiment <?php error_reporting(E_ALL | E_STRICT); ini_set('display_errors', 1); $mageFilename = 'app/Mage.php'; require_once $mageFilename; Mage::setIsDeveloperMode(true); umask(0); Mage::app(); // … our code …
  • 29. — developer’s Swiss knife DEBUGGING and PROFILING
  • 30. xDebug Installation http://xdebug.org/download.php Setting up xdebug.profiler_enable_trigger=on xdebug.remote_autostart=off xdebug.remote_enable=1 xdebug.remote_host="127.0.0.1" xdebug.remote_port=9000 xdebug.remote_handler="dbgp" xdebug.idekey="netbeans" xdebug.collect_vars=on xdebug.collect_params=4 xdebug.show_local_vars=on xdebug.var_display_max_depth=5 xdebug.show_exception_trace=on zend_extension=/usr/lib/php5/20090626+lfs/xdebug.so ; zend_extension_ts="c:phpextphp_xdebug-2.0.1-5.2.1.dll"
  • 31. xDebug Setting up NetBeans IDE
  • 32. xDebug Well, what good will that do? http://example.com/index.php?XDEBUG_SESSION_START=netbeans
  • 33. xDebug http://example.com/index.php?XDEBUG_SESSION_START=netbeans Xdebug helper http://bit.ly/KuCo2c easy Xdebug http://bit.ly/LKpvjC
  • 34. xDebug Profiling xdebug.profiler_enable=1
  • 35. xDebug — profiling Logs visualization Webgrind http://bit.ly/LXMGFJ Kcachegrind http://bit.ly/KGzyAw WinCacheGrind http://bit.ly/Nh4iPY Xdebugtoolkit http://bit.ly/LmB4t9 MacCallGrind http://bit.ly/LlerGS CachegrindVisualizer http://bit.ly/OD6dLy
  • 38. <config> <modules> <Some_Module> <active>false</active> <Some_Module> </modules> </config>
  • 39.
  • 40. Magento Connect — developer tools Commerce Bug http://bit.ly/M8ggqh
  • 41. Magento Connect — developer tools Developer Toolbar for Magento http://bit.ly/LnSW8s
  • 42. Magento Connect — developer tools Advanced Developer Tools http://bit.ly/Lo1Vqa Only for versions 1.6.1 and earlier
  • 43. Magento Connect — developer tools Developer Toolbar http://bit.ly/LnD1Hk
  • 44. Magento Connect — developer tools Magento FirePHP http://bit.ly/LnYGyX Mage::helper('firephp')->send('Lorem ipsum sit amet ..'); Mage::helper('firephp')->debug(Mage::getModel('catalog/product')->load(54));
  • 45. Magento Connect — developer tools Developer Helper http://bit.ly/OLauwz
  • 46. THANK YOU FOR YOUR ATTENTION pavel@belvg.com