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

Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxMichelangelo van Dam
 
購物車程式架構簡介
購物車程式架構簡介購物車程式架構簡介
購物車程式架構簡介Jace Ju
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11Michelangelo van Dam
 
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 sitereferences
 
Doctrine 2
Doctrine 2Doctrine 2
Doctrine 2zfconfua
 
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 PerformanceIvan Chepurnyi
 
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 CachingErick Hitter
 
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 CairoMohamed Mosaad
 
[PHP] Zend_Db (Zend Framework)
[PHP] Zend_Db (Zend Framework)[PHP] Zend_Db (Zend Framework)
[PHP] Zend_Db (Zend Framework)Jun Shimizu
 
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 UnConRafael Dohms
 
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 railsTse-Ching Ho
 
PHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くためにPHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くためにYuya Takeyama
 
td_mxc_rubyrails_shin
td_mxc_rubyrails_shintd_mxc_rubyrails_shin
td_mxc_rubyrails_shintutorialsruby
 
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 projectMichelangelo 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

лікування гепатитів на асоціацію
лікування гепатитів на асоціаціюлікування гепатитів на асоціацію
лікування гепатитів на асоціаціюVoyevidka_OS
 
хронічний гастрит
хронічний гастритхронічний гастрит
хронічний гастритVoyevidka_OS
 
Pancreatitis chronic лiкарi
Pancreatitis chronic лiкарiPancreatitis chronic лiкарi
Pancreatitis chronic лiкарiVoyevidka_OS
 
Виразкова хвороба
Виразкова хворобаВиразкова хвороба
Виразкова хворобаVoyevidka_OS
 
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)Pavel Novitsky
 
Ulcer without films
Ulcer without filmsUlcer without films
Ulcer without filmsVoyevidka_OS
 
Панкреатит
ПанкреатитПанкреатит
ПанкреатитVoyevidka_OS
 
бронхіальна астма
бронхіальна астмабронхіальна астма
бронхіальна астмаVoyevidka_OS
 
Investment alternatives
Investment alternativesInvestment alternatives
Investment alternativesDr. Amit Joshi
 
Market selection in international marketing
Market selection in international marketingMarket selection in international marketing
Market selection in international marketingDr. Amit Joshi
 

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
 
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 PHPStormMichelangelo van Dam
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applicationschartjes
 
Modernising Legacy Code
Modernising Legacy CodeModernising Legacy Code
Modernising Legacy CodeSamThePHPDev
 
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 tek12Michelangelo van Dam
 
Php tips-and-tricks4128
Php tips-and-tricks4128Php tips-and-tricks4128
Php tips-and-tricks4128PrinceGuru MS
 
PHP security audits
PHP security auditsPHP security audits
PHP security auditsDamien Seguy
 
Тестирование и Django
Тестирование и DjangoТестирование и Django
Тестирование и DjangoMoscowDjango
 
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 2012Michelangelo van Dam
 
Dealing with Legacy PHP Applications
Dealing with Legacy PHP ApplicationsDealing with Legacy PHP Applications
Dealing with Legacy PHP ApplicationsClinton Dreisbach
 
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 processingCareer at Elsner
 
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 - 4DevelopersKacper Gunia
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Shinya Ohyanagi
 
Ch ch-changes cake php2
Ch ch-changes cake php2Ch ch-changes cake php2
Ch ch-changes cake php2markstory
 
PHP tips and tricks
PHP tips and tricks PHP tips and tricks
PHP tips and tricks Damien Seguy
 
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 2007Rabble .
 
Optimization in django orm
Optimization in django ormOptimization in django orm
Optimization in django ormDenys Levchenko
 

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

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 

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