SlideShare a Scribd company logo
1 of 28
Debugging WP plugins with
          Xdebug
        and Eclipse.




                Cascina Roccafranca – Torino – 16 giugno 2012
Walter Dal Mut – walterdalmut.com – walter.dalmut@corley.it - @walterdalmut

                                                                      1       di   28
Debugging PHP App/Scripts
β€’ Using var_dump or print_r typically in conjunction with die
 function.
β€’ Generate tons of logs
   β€’ File
   β€’ Database
   β€’ Etc.
β€’ Using debug support
   β€’ Xdebug
   β€’ Zend Debugger


                             Corley S.r.l.
                             Piazza Statuto 10, Torino (10122)   2   di   28
                             P.Iva 10669790015
                             www.corley.it
Introduction to xdebug
β€’ What is it?
   – A PHP Extension designed by Derick Rethans
β€’ Features
   – Stack Traces
   – Execution Traces
   – Memory Allocation
   – Code Profiling
   – Code Coverage Analysis
   – Interactive Debugging


                             Corley S.r.l.
                             Piazza Statuto 10, Torino (10122)   3   di   28
                             P.Iva 10669790015
                             www.corley.it
Useful information about xdebug
β€’ Main website
   – www.xdebug.org
β€’ Source code
   – https://github.com/derickr/xdebug
β€’ Bug Tracking
   – http://bugs.xdebug.org/my_view_page.php




                       Corley S.r.l.
                       Piazza Statuto 10, Torino (10122)   4   di   28
                       P.Iva 10669790015
                       www.corley.it
Why debugging applications with xdebug

β€’   Works var_dump +/- die well?
     – Always debatable, not always true
     – Conditional debugging may be complex
     – Big scopes could be hard to read and understand
β€’   Xdebug improve var_dump and add useful inspection functions
      β€’ xdebug_* functions
β€’   Xdebug
     – Step by step interaction
     – Inline variable modifications
     – Remote debugging
     – Conditional debugging



                                     Corley S.r.l.
                                     Piazza Statuto 10, Torino (10122)   5   di   28
                                     P.Iva 10669790015
                                     www.corley.it
Obtaining xdebug - Linux
β€’   Use distribution package installer
      – Example on Debian - Ubuntu
            β€’ Install
                 – apt-get install php5-xdebug
            β€’ Dedicated configuration file
                 – /etc/php5/conf.d/xdebug.ini
β€’   Install using PECL package manager
      – Install
            β€’ sudo pecl install xdebug
      – Add into your php.ini
            β€’ zend_extension=”/path/to/xdebug.so” β†’ complete path
β€’   Compile by your-self
       β€’ phpize οƒ  configure οƒ  make οƒ  make install



                                 Corley S.r.l.
                                 Piazza Statuto 10, Torino (10122)   6   di   28
                                 P.Iva 10669790015
                                 www.corley.it
Obtaining xdebug - Windows
β€’ Use a self-install package that includes xdebug
   – Xampp (Activate it into your php.ini)
   – Wamp (Activate it through dedicated menus)
β€’ Download the xdebug library (DLL) and copy/paste into your
 PHP extension folder
   – Download the library from
      β€’ http://www.xdebug.org
      β€’ http://pecl4win.php.net
      β€’ http://windows.php.net


                             Corley S.r.l.
                             Piazza Statuto 10, Torino (10122)   7   di   28
                             P.Iva 10669790015
                             www.corley.it
Obtaining xdebug – MAC OS
β€’ Use a self-install package that includes xdebug
   – MAMP (Activate it into your php.ini)
β€’ Download the xdebug library (.so) and copy/paste into your PHP
 extension folder
β€’ Compile xdebug by your-self (phpize)
β€’ Use BREW package manager
    β€’   brew install xdebug




                               Corley S.r.l.
                               Piazza Statuto 10, Torino (10122)   8   di   28
                               P.Iva 10669790015
                               www.corley.it
Interactive Debugging
β€’ Enable in php.ini
   – zend_extension=/path/to/xdebug.so
   – Pay attention on
       β€’ Use complete path
       β€’ Ignore extension=xdebug.so because it causes problems
   – Typical you have to setup only four directives
       β€’ xdebug.remote_enable (On) [default as Off]
       β€’ xdebug.remote_host (localhost) [default]
       β€’ xdebug.remote_port (9000) [default]
       β€’ xdebug.remote_handler (dbgp) [default]


                                Corley S.r.l.
                                Piazza Statuto 10, Torino (10122)   9   di   28
                                P.Iva 10669790015
                                www.corley.it
Xdebug and other extensions
Xdebug does not work together with the Zend Optimizer or any other
extension that deals with PHP's internals (DBG, APD, ioncube etc). This
is due to compatibility problems with those modules.




                                  Corley S.r.l.
                                  Piazza Statuto 10, Torino (10122)   10   di   28
                                  P.Iva 10669790015
                                  www.corley.it
Strategies of remote debugging




       Corley S.r.l.                       www.corley.it
       Piazza Statuto 10, Torino (10122)   info@corley.it           11   di   28
       P.Iva 10669790015                   Tel. (+39) 011 4365278
Start with WP project
β€’ Download WP
   – http://wordpress.org/download/
β€’ Unzip it into an external eclipse workspace dir
   – /home/walter/mywp
   – C:Documentswalterslidesmywp
β€’ Install WP normally using web pages




                                   Corley S.r.l.
                                   Piazza Statuto 10, Torino (10122)   12   di   28
                                   P.Iva 10669790015
                                   www.corley.it
Plugin source code
β€’ A simple plugin that append twitter news of
 wpcon.it
β€’ Fork it on github
   – https://github.com/wdalmut/wpcon-plugin




                     Corley S.r.l.
                     Piazza Statuto 10, Torino (10122)   13   di   28
                     P.Iva 10669790015
                     www.corley.it
Plugin Output




                Corley S.r.l.
                Piazza Statuto 10, Torino (10122)   14   di   28
                P.Iva 10669790015
                www.corley.it
Create PHP project on eclipse




                 Corley S.r.l.
                 Piazza Statuto 10, Torino (10122)   15   di   28
                 P.Iva 10669790015
                 www.corley.it
Setup WPCON dev server
β€’   Configure your local Apache2
     – Create vhost for wpcon.local
β€’   Open Eclipse IDE
     – Window β†’ Preferences β†’ PHP β†’ PHP Servers
         β€’ Add a new server for the wpcon.local configuration
              – Name: WPCON (whatever you want, it's just a label)
              – Base URL: http://wpcon.local (the base url of local server)
              – Local Web Root: C:UsersWalterslideswordpress (Path of wp)
     – Window β†’ Preferences β†’ PHP β†’ Debug
         β€’ Check that xdebug is installed and configured




                                      Corley S.r.l.
                                      Piazza Statuto 10, Torino (10122)   16   di   28
                                      P.Iva 10669790015
                                      www.corley.it
17   di   28
Now we are ready to debug application

β€’ Creates or copy files for this plugin into your project
    β€’ If you prefer use git clone
β€’ Activate this plugin using the WP administrator center




                               Corley S.r.l.
                               Piazza Statuto 10, Torino (10122)   18   di   28
                               P.Iva 10669790015
                               www.corley.it
Debugging in Eclipse IDE
β€’ A debug session
   – Starts with command β€œDebug as”
       β€’ Debug as β†’ PHP Web Application
            – ALT + SHIFT + D, W
   – It terminates with the explicit stop command
β€’ Breakpoint
   – It is an explicit marker that stop the code execution at a particular
      point of your software.
β€’ Inspection windows
   – When the debugger waits for a command you can see and
      modify variables in the scope.

                                   Corley S.r.l.
                                   Piazza Statuto 10, Torino (10122)   19   di   28
                                   P.Iva 10669790015
                                   www.corley.it
Debugging flow control
β€’   Resume β†’ Wake up and run until a debug target
β€’   Pause β†’ Sleep this session
β€’   Stop β†’ Close this debug session
β€’   Disconnect β†’ Close debug but go ahead
β€’   StepIn β†’ Execute a step inside a method/function
β€’   StepOver β†’ Execute a step but don't go into.
β€’   StepReturn β†’ Return from a method which has been stepped into




                                     Corley S.r.l.
                                     Piazza Statuto 10, Torino (10122)   23   di   28
                                     P.Iva 10669790015
                                     www.corley.it
Breakpoints and conditions
β€’ You can add breakpoints
  – Double-click on left part of eclipse code view
β€’ You can add conditional breakpoints
  – Add a normal breakpoint, right-click on this one and select
    that you need a condition
  – Add a normal PHP condition




                              Corley S.r.l.
                              Piazza Statuto 10, Torino (10122)   24   di   28
                              P.Iva 10669790015
                              www.corley.it
Conditional breakpoints (2)
Conditional breakpoints simplify your life in debugging parts of
code with conditions. A simple recursive example:

function factorial($n) {
    if ($n === 0) {
        return 1;
    } else {
        return $n * factorial($n-1);
    }
}

echo factorial(12);




                                Corley S.r.l.
                                Piazza Statuto 10, Torino (10122)   25   di   28
                                P.Iva 10669790015
                                www.corley.it
Online updates




                 Corley S.r.l.
                 Piazza Statuto 10, Torino (10122)   26   di   28
                 P.Iva 10669790015
                 www.corley.it
Online updates (2)




                Corley S.r.l.
                Piazza Statuto 10, Torino (10122)   27   di   28
                P.Iva 10669790015
                www.corley.it
THANK YOU FOR LISTENING
                   Walter Dal Mut
walterdalmut.com - walter.dalmut@corley.it -@walterdalmut




           Cascina Roccafranca – Torino – 16 giugno 2012


                                                           28   di   28

More Related Content

Similar to Remote debugging with Xdebug and Eclispe

Troubleshooting .net core on linux
Troubleshooting .net core on linuxTroubleshooting .net core on linux
Troubleshooting .net core on linuxPavel Klimiankou
Β 
Ten years analysing large code bases: a perspective
Ten years analysing large code bases: a perspectiveTen years analysing large code bases: a perspective
Ten years analysing large code bases: a perspectiveRoberto Di Cosmo
Β 
PythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummiesPythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummiesTatiana Al-Chueyr
Β 
IoTivity for Automotive: meta-ocf-automotive tutorial
IoTivity for Automotive: meta-ocf-automotive tutorialIoTivity for Automotive: meta-ocf-automotive tutorial
IoTivity for Automotive: meta-ocf-automotive tutorialSamsung Open Source Group
Β 
DDD (Debugger Driven Development)
DDD (Debugger Driven Development)DDD (Debugger Driven Development)
DDD (Debugger Driven Development)Carlos Granados
Β 
Developing Android Platform Tools
Developing Android Platform ToolsDeveloping Android Platform Tools
Developing Android Platform ToolsOpersys inc.
Β 
How go makes us faster (May 2015)
How go makes us faster (May 2015)How go makes us faster (May 2015)
How go makes us faster (May 2015)Wilfried Schobeiri
Β 
Modernisation of Legacy PHP Applications to Symfony2 - Symfony Live Berlin 2012
Modernisation of Legacy PHP Applications to Symfony2 - Symfony Live Berlin 2012Modernisation of Legacy PHP Applications to Symfony2 - Symfony Live Berlin 2012
Modernisation of Legacy PHP Applications to Symfony2 - Symfony Live Berlin 2012Fabrice Bernhard
Β 
Tomcat from a cluster to the cloud on RP3
Tomcat from a cluster to the cloud on RP3Tomcat from a cluster to the cloud on RP3
Tomcat from a cluster to the cloud on RP3Jean-Frederic Clere
Β 
Import golang; struct microservice
Import golang; struct microserviceImport golang; struct microservice
Import golang; struct microserviceGiulio De Donato
Β 
Continuous Delivery for Python Developers – PyCon Otto
Continuous Delivery for Python Developers – PyCon OttoContinuous Delivery for Python Developers – PyCon Otto
Continuous Delivery for Python Developers – PyCon OttoPeter Bittner
Β 
Free Sorftware Research at Irill (highlights)
Free Sorftware Research at Irill (highlights)Free Sorftware Research at Irill (highlights)
Free Sorftware Research at Irill (highlights)Roberto Di Cosmo
Β 
Containers without docker | DevNation Tech Talk
Containers without docker | DevNation Tech TalkContainers without docker | DevNation Tech Talk
Containers without docker | DevNation Tech TalkRed Hat Developers
Β 
Docker for business: How I stopped worrying about antipatterns
Docker for business: How I stopped worrying about antipatternsDocker for business: How I stopped worrying about antipatterns
Docker for business: How I stopped worrying about antipatternsLenses.io
Β 
Build reliable, traceable, distributed systems with ZeroMQ
Build reliable, traceable, distributed systems with ZeroMQBuild reliable, traceable, distributed systems with ZeroMQ
Build reliable, traceable, distributed systems with ZeroMQRobin Xiao
Β 
Buildout: creating and deploying repeatable applications in python
Buildout: creating and deploying repeatable applications in pythonBuildout: creating and deploying repeatable applications in python
Buildout: creating and deploying repeatable applications in pythonCodeSyntax
Β 
EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4Max Kleiner
Β 

Similar to Remote debugging with Xdebug and Eclispe (20)

Xdebug
XdebugXdebug
Xdebug
Β 
Troubleshooting .net core on linux
Troubleshooting .net core on linuxTroubleshooting .net core on linux
Troubleshooting .net core on linux
Β 
Ten years analysing large code bases: a perspective
Ten years analysing large code bases: a perspectiveTen years analysing large code bases: a perspective
Ten years analysing large code bases: a perspective
Β 
PythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummiesPythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummies
Β 
IoTivity for Automotive: meta-ocf-automotive tutorial
IoTivity for Automotive: meta-ocf-automotive tutorialIoTivity for Automotive: meta-ocf-automotive tutorial
IoTivity for Automotive: meta-ocf-automotive tutorial
Β 
DDD (Debugger Driven Development)
DDD (Debugger Driven Development)DDD (Debugger Driven Development)
DDD (Debugger Driven Development)
Β 
Developing Android Platform Tools
Developing Android Platform ToolsDeveloping Android Platform Tools
Developing Android Platform Tools
Β 
Iotivity atmel-20150328rzr
Iotivity atmel-20150328rzrIotivity atmel-20150328rzr
Iotivity atmel-20150328rzr
Β 
How go makes us faster (May 2015)
How go makes us faster (May 2015)How go makes us faster (May 2015)
How go makes us faster (May 2015)
Β 
Modernisation of Legacy PHP Applications to Symfony2 - Symfony Live Berlin 2012
Modernisation of Legacy PHP Applications to Symfony2 - Symfony Live Berlin 2012Modernisation of Legacy PHP Applications to Symfony2 - Symfony Live Berlin 2012
Modernisation of Legacy PHP Applications to Symfony2 - Symfony Live Berlin 2012
Β 
Tomcat from a cluster to the cloud on RP3
Tomcat from a cluster to the cloud on RP3Tomcat from a cluster to the cloud on RP3
Tomcat from a cluster to the cloud on RP3
Β 
Import golang; struct microservice
Import golang; struct microserviceImport golang; struct microservice
Import golang; struct microservice
Β 
Continuous Delivery for Python Developers – PyCon Otto
Continuous Delivery for Python Developers – PyCon OttoContinuous Delivery for Python Developers – PyCon Otto
Continuous Delivery for Python Developers – PyCon Otto
Β 
Free Sorftware Research at Irill (highlights)
Free Sorftware Research at Irill (highlights)Free Sorftware Research at Irill (highlights)
Free Sorftware Research at Irill (highlights)
Β 
Tizen store-z1-20150228rzr
Tizen store-z1-20150228rzrTizen store-z1-20150228rzr
Tizen store-z1-20150228rzr
Β 
Containers without docker | DevNation Tech Talk
Containers without docker | DevNation Tech TalkContainers without docker | DevNation Tech Talk
Containers without docker | DevNation Tech Talk
Β 
Docker for business: How I stopped worrying about antipatterns
Docker for business: How I stopped worrying about antipatternsDocker for business: How I stopped worrying about antipatterns
Docker for business: How I stopped worrying about antipatterns
Β 
Build reliable, traceable, distributed systems with ZeroMQ
Build reliable, traceable, distributed systems with ZeroMQBuild reliable, traceable, distributed systems with ZeroMQ
Build reliable, traceable, distributed systems with ZeroMQ
Β 
Buildout: creating and deploying repeatable applications in python
Buildout: creating and deploying repeatable applications in pythonBuildout: creating and deploying repeatable applications in python
Buildout: creating and deploying repeatable applications in python
Β 
EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4
Β 

More from Corley S.r.l.

Aws rekognition - riconoscimento facciale
Aws rekognition  - riconoscimento faccialeAws rekognition  - riconoscimento facciale
Aws rekognition - riconoscimento faccialeCorley S.r.l.
Β 
AWSome day 2018 - scalability and cost optimization with container services
AWSome day 2018 - scalability and cost optimization with container servicesAWSome day 2018 - scalability and cost optimization with container services
AWSome day 2018 - scalability and cost optimization with container servicesCorley S.r.l.
Β 
AWSome day 2018 - API serverless with aws
AWSome day 2018  - API serverless with awsAWSome day 2018  - API serverless with aws
AWSome day 2018 - API serverless with awsCorley S.r.l.
Β 
AWSome day 2018 - database in cloud
AWSome day 2018 -  database in cloudAWSome day 2018 -  database in cloud
AWSome day 2018 - database in cloudCorley S.r.l.
Β 
Trace your micro-services oriented application with Zipkin and OpenTracing
Trace your micro-services oriented application with Zipkin and OpenTracing Trace your micro-services oriented application with Zipkin and OpenTracing
Trace your micro-services oriented application with Zipkin and OpenTracing Corley S.r.l.
Β 
Apiconf - The perfect REST solution
Apiconf - The perfect REST solutionApiconf - The perfect REST solution
Apiconf - The perfect REST solutionCorley S.r.l.
Β 
Apiconf - Doc Driven Development
Apiconf - Doc Driven DevelopmentApiconf - Doc Driven Development
Apiconf - Doc Driven DevelopmentCorley S.r.l.
Β 
Authentication and authorization in res tful infrastructures
Authentication and authorization in res tful infrastructuresAuthentication and authorization in res tful infrastructures
Authentication and authorization in res tful infrastructuresCorley S.r.l.
Β 
Flexibility and scalability of costs in serverless infrastructures
Flexibility and scalability of costs in serverless infrastructuresFlexibility and scalability of costs in serverless infrastructures
Flexibility and scalability of costs in serverless infrastructuresCorley S.r.l.
Β 
CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application
CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented applicationCloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application
CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented applicationCorley S.r.l.
Β 
React vs Angular2
React vs Angular2React vs Angular2
React vs Angular2Corley S.r.l.
Β 
A single language for backend and frontend from AngularJS to cloud with Clau...
A single language for backend and frontend  from AngularJS to cloud with Clau...A single language for backend and frontend  from AngularJS to cloud with Clau...
A single language for backend and frontend from AngularJS to cloud with Clau...Corley S.r.l.
Β 
AngularJS: Service, factory & provider
AngularJS: Service, factory & providerAngularJS: Service, factory & provider
AngularJS: Service, factory & providerCorley S.r.l.
Β 
The advantage of developing with TypeScript
The advantage of developing with TypeScript The advantage of developing with TypeScript
The advantage of developing with TypeScript Corley S.r.l.
Β 
Angular coding: from project management to web and mobile deploy
Angular coding: from project management to web and mobile deployAngular coding: from project management to web and mobile deploy
Angular coding: from project management to web and mobile deployCorley S.r.l.
Β 
Corley cloud angular in cloud
Corley cloud   angular in cloudCorley cloud   angular in cloud
Corley cloud angular in cloudCorley S.r.l.
Β 
Measure your app internals with InfluxDB and Symfony2
Measure your app internals with InfluxDB and Symfony2Measure your app internals with InfluxDB and Symfony2
Measure your app internals with InfluxDB and Symfony2Corley S.r.l.
Β 
Read Twitter Stream and Tweet back pictures with Raspberry Pi & AWS Lambda
Read Twitter Stream and Tweet back pictures with Raspberry Pi & AWS LambdaRead Twitter Stream and Tweet back pictures with Raspberry Pi & AWS Lambda
Read Twitter Stream and Tweet back pictures with Raspberry Pi & AWS LambdaCorley S.r.l.
Β 
Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour L...
Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour L...Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour L...
Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour L...Corley S.r.l.
Β 
Middleware PHP - A simple micro-framework
Middleware PHP - A simple micro-frameworkMiddleware PHP - A simple micro-framework
Middleware PHP - A simple micro-frameworkCorley S.r.l.
Β 

More from Corley S.r.l. (20)

Aws rekognition - riconoscimento facciale
Aws rekognition  - riconoscimento faccialeAws rekognition  - riconoscimento facciale
Aws rekognition - riconoscimento facciale
Β 
AWSome day 2018 - scalability and cost optimization with container services
AWSome day 2018 - scalability and cost optimization with container servicesAWSome day 2018 - scalability and cost optimization with container services
AWSome day 2018 - scalability and cost optimization with container services
Β 
AWSome day 2018 - API serverless with aws
AWSome day 2018  - API serverless with awsAWSome day 2018  - API serverless with aws
AWSome day 2018 - API serverless with aws
Β 
AWSome day 2018 - database in cloud
AWSome day 2018 -  database in cloudAWSome day 2018 -  database in cloud
AWSome day 2018 - database in cloud
Β 
Trace your micro-services oriented application with Zipkin and OpenTracing
Trace your micro-services oriented application with Zipkin and OpenTracing Trace your micro-services oriented application with Zipkin and OpenTracing
Trace your micro-services oriented application with Zipkin and OpenTracing
Β 
Apiconf - The perfect REST solution
Apiconf - The perfect REST solutionApiconf - The perfect REST solution
Apiconf - The perfect REST solution
Β 
Apiconf - Doc Driven Development
Apiconf - Doc Driven DevelopmentApiconf - Doc Driven Development
Apiconf - Doc Driven Development
Β 
Authentication and authorization in res tful infrastructures
Authentication and authorization in res tful infrastructuresAuthentication and authorization in res tful infrastructures
Authentication and authorization in res tful infrastructures
Β 
Flexibility and scalability of costs in serverless infrastructures
Flexibility and scalability of costs in serverless infrastructuresFlexibility and scalability of costs in serverless infrastructures
Flexibility and scalability of costs in serverless infrastructures
Β 
CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application
CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented applicationCloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application
CloudConf2017 - Deploy, Scale & Coordinate a microservice oriented application
Β 
React vs Angular2
React vs Angular2React vs Angular2
React vs Angular2
Β 
A single language for backend and frontend from AngularJS to cloud with Clau...
A single language for backend and frontend  from AngularJS to cloud with Clau...A single language for backend and frontend  from AngularJS to cloud with Clau...
A single language for backend and frontend from AngularJS to cloud with Clau...
Β 
AngularJS: Service, factory & provider
AngularJS: Service, factory & providerAngularJS: Service, factory & provider
AngularJS: Service, factory & provider
Β 
The advantage of developing with TypeScript
The advantage of developing with TypeScript The advantage of developing with TypeScript
The advantage of developing with TypeScript
Β 
Angular coding: from project management to web and mobile deploy
Angular coding: from project management to web and mobile deployAngular coding: from project management to web and mobile deploy
Angular coding: from project management to web and mobile deploy
Β 
Corley cloud angular in cloud
Corley cloud   angular in cloudCorley cloud   angular in cloud
Corley cloud angular in cloud
Β 
Measure your app internals with InfluxDB and Symfony2
Measure your app internals with InfluxDB and Symfony2Measure your app internals with InfluxDB and Symfony2
Measure your app internals with InfluxDB and Symfony2
Β 
Read Twitter Stream and Tweet back pictures with Raspberry Pi & AWS Lambda
Read Twitter Stream and Tweet back pictures with Raspberry Pi & AWS LambdaRead Twitter Stream and Tweet back pictures with Raspberry Pi & AWS Lambda
Read Twitter Stream and Tweet back pictures with Raspberry Pi & AWS Lambda
Β 
Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour L...
Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour L...Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour L...
Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour L...
Β 
Middleware PHP - A simple micro-framework
Middleware PHP - A simple micro-frameworkMiddleware PHP - A simple micro-framework
Middleware PHP - A simple micro-framework
Β 

Recently uploaded

Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
Β 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
Β 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
Β 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
Β 
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
Β 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
Β 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
Β 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
Β 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
Β 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
Β 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
Β 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
Β 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
Β 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
Β 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
Β 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
Β 
Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)
Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)
Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)Wonjun Hwang
Β 

Recently uploaded (20)

Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
Β 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
Β 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Β 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
Β 
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
Β 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
Β 
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
Β 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
Β 
Hot Sexy call girls in Panjabi Bagh πŸ” 9953056974 πŸ” Delhi escort Service
Hot Sexy call girls in Panjabi Bagh πŸ” 9953056974 πŸ” Delhi escort ServiceHot Sexy call girls in Panjabi Bagh πŸ” 9953056974 πŸ” Delhi escort Service
Hot Sexy call girls in Panjabi Bagh πŸ” 9953056974 πŸ” Delhi escort Service
Β 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
Β 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Β 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
Β 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Β 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
Β 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Β 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
Β 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Β 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
Β 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
Β 
Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)
Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)
Bun (KitWorks Team Study λ…Έλ³„λ§ˆλ£¨ λ°œν‘œ 2024.4.22)
Β 

Remote debugging with Xdebug and Eclispe

  • 1. Debugging WP plugins with Xdebug and Eclipse. Cascina Roccafranca – Torino – 16 giugno 2012 Walter Dal Mut – walterdalmut.com – walter.dalmut@corley.it - @walterdalmut 1 di 28
  • 2. Debugging PHP App/Scripts β€’ Using var_dump or print_r typically in conjunction with die function. β€’ Generate tons of logs β€’ File β€’ Database β€’ Etc. β€’ Using debug support β€’ Xdebug β€’ Zend Debugger Corley S.r.l. Piazza Statuto 10, Torino (10122) 2 di 28 P.Iva 10669790015 www.corley.it
  • 3. Introduction to xdebug β€’ What is it? – A PHP Extension designed by Derick Rethans β€’ Features – Stack Traces – Execution Traces – Memory Allocation – Code Profiling – Code Coverage Analysis – Interactive Debugging Corley S.r.l. Piazza Statuto 10, Torino (10122) 3 di 28 P.Iva 10669790015 www.corley.it
  • 4. Useful information about xdebug β€’ Main website – www.xdebug.org β€’ Source code – https://github.com/derickr/xdebug β€’ Bug Tracking – http://bugs.xdebug.org/my_view_page.php Corley S.r.l. Piazza Statuto 10, Torino (10122) 4 di 28 P.Iva 10669790015 www.corley.it
  • 5. Why debugging applications with xdebug β€’ Works var_dump +/- die well? – Always debatable, not always true – Conditional debugging may be complex – Big scopes could be hard to read and understand β€’ Xdebug improve var_dump and add useful inspection functions β€’ xdebug_* functions β€’ Xdebug – Step by step interaction – Inline variable modifications – Remote debugging – Conditional debugging Corley S.r.l. Piazza Statuto 10, Torino (10122) 5 di 28 P.Iva 10669790015 www.corley.it
  • 6. Obtaining xdebug - Linux β€’ Use distribution package installer – Example on Debian - Ubuntu β€’ Install – apt-get install php5-xdebug β€’ Dedicated configuration file – /etc/php5/conf.d/xdebug.ini β€’ Install using PECL package manager – Install β€’ sudo pecl install xdebug – Add into your php.ini β€’ zend_extension=”/path/to/xdebug.so” β†’ complete path β€’ Compile by your-self β€’ phpize οƒ  configure οƒ  make οƒ  make install Corley S.r.l. Piazza Statuto 10, Torino (10122) 6 di 28 P.Iva 10669790015 www.corley.it
  • 7. Obtaining xdebug - Windows β€’ Use a self-install package that includes xdebug – Xampp (Activate it into your php.ini) – Wamp (Activate it through dedicated menus) β€’ Download the xdebug library (DLL) and copy/paste into your PHP extension folder – Download the library from β€’ http://www.xdebug.org β€’ http://pecl4win.php.net β€’ http://windows.php.net Corley S.r.l. Piazza Statuto 10, Torino (10122) 7 di 28 P.Iva 10669790015 www.corley.it
  • 8. Obtaining xdebug – MAC OS β€’ Use a self-install package that includes xdebug – MAMP (Activate it into your php.ini) β€’ Download the xdebug library (.so) and copy/paste into your PHP extension folder β€’ Compile xdebug by your-self (phpize) β€’ Use BREW package manager β€’ brew install xdebug Corley S.r.l. Piazza Statuto 10, Torino (10122) 8 di 28 P.Iva 10669790015 www.corley.it
  • 9. Interactive Debugging β€’ Enable in php.ini – zend_extension=/path/to/xdebug.so – Pay attention on β€’ Use complete path β€’ Ignore extension=xdebug.so because it causes problems – Typical you have to setup only four directives β€’ xdebug.remote_enable (On) [default as Off] β€’ xdebug.remote_host (localhost) [default] β€’ xdebug.remote_port (9000) [default] β€’ xdebug.remote_handler (dbgp) [default] Corley S.r.l. Piazza Statuto 10, Torino (10122) 9 di 28 P.Iva 10669790015 www.corley.it
  • 10. Xdebug and other extensions Xdebug does not work together with the Zend Optimizer or any other extension that deals with PHP's internals (DBG, APD, ioncube etc). This is due to compatibility problems with those modules. Corley S.r.l. Piazza Statuto 10, Torino (10122) 10 di 28 P.Iva 10669790015 www.corley.it
  • 11. Strategies of remote debugging Corley S.r.l. www.corley.it Piazza Statuto 10, Torino (10122) info@corley.it 11 di 28 P.Iva 10669790015 Tel. (+39) 011 4365278
  • 12. Start with WP project β€’ Download WP – http://wordpress.org/download/ β€’ Unzip it into an external eclipse workspace dir – /home/walter/mywp – C:Documentswalterslidesmywp β€’ Install WP normally using web pages Corley S.r.l. Piazza Statuto 10, Torino (10122) 12 di 28 P.Iva 10669790015 www.corley.it
  • 13. Plugin source code β€’ A simple plugin that append twitter news of wpcon.it β€’ Fork it on github – https://github.com/wdalmut/wpcon-plugin Corley S.r.l. Piazza Statuto 10, Torino (10122) 13 di 28 P.Iva 10669790015 www.corley.it
  • 14. Plugin Output Corley S.r.l. Piazza Statuto 10, Torino (10122) 14 di 28 P.Iva 10669790015 www.corley.it
  • 15. Create PHP project on eclipse Corley S.r.l. Piazza Statuto 10, Torino (10122) 15 di 28 P.Iva 10669790015 www.corley.it
  • 16. Setup WPCON dev server β€’ Configure your local Apache2 – Create vhost for wpcon.local β€’ Open Eclipse IDE – Window β†’ Preferences β†’ PHP β†’ PHP Servers β€’ Add a new server for the wpcon.local configuration – Name: WPCON (whatever you want, it's just a label) – Base URL: http://wpcon.local (the base url of local server) – Local Web Root: C:UsersWalterslideswordpress (Path of wp) – Window β†’ Preferences β†’ PHP β†’ Debug β€’ Check that xdebug is installed and configured Corley S.r.l. Piazza Statuto 10, Torino (10122) 16 di 28 P.Iva 10669790015 www.corley.it
  • 17. 17 di 28
  • 18. Now we are ready to debug application β€’ Creates or copy files for this plugin into your project β€’ If you prefer use git clone β€’ Activate this plugin using the WP administrator center Corley S.r.l. Piazza Statuto 10, Torino (10122) 18 di 28 P.Iva 10669790015 www.corley.it
  • 19. Debugging in Eclipse IDE β€’ A debug session – Starts with command β€œDebug as” β€’ Debug as β†’ PHP Web Application – ALT + SHIFT + D, W – It terminates with the explicit stop command β€’ Breakpoint – It is an explicit marker that stop the code execution at a particular point of your software. β€’ Inspection windows – When the debugger waits for a command you can see and modify variables in the scope. Corley S.r.l. Piazza Statuto 10, Torino (10122) 19 di 28 P.Iva 10669790015 www.corley.it
  • 20.
  • 21.
  • 22.
  • 23. Debugging flow control β€’ Resume β†’ Wake up and run until a debug target β€’ Pause β†’ Sleep this session β€’ Stop β†’ Close this debug session β€’ Disconnect β†’ Close debug but go ahead β€’ StepIn β†’ Execute a step inside a method/function β€’ StepOver β†’ Execute a step but don't go into. β€’ StepReturn β†’ Return from a method which has been stepped into Corley S.r.l. Piazza Statuto 10, Torino (10122) 23 di 28 P.Iva 10669790015 www.corley.it
  • 24. Breakpoints and conditions β€’ You can add breakpoints – Double-click on left part of eclipse code view β€’ You can add conditional breakpoints – Add a normal breakpoint, right-click on this one and select that you need a condition – Add a normal PHP condition Corley S.r.l. Piazza Statuto 10, Torino (10122) 24 di 28 P.Iva 10669790015 www.corley.it
  • 25. Conditional breakpoints (2) Conditional breakpoints simplify your life in debugging parts of code with conditions. A simple recursive example: function factorial($n) { if ($n === 0) { return 1; } else { return $n * factorial($n-1); } } echo factorial(12); Corley S.r.l. Piazza Statuto 10, Torino (10122) 25 di 28 P.Iva 10669790015 www.corley.it
  • 26. Online updates Corley S.r.l. Piazza Statuto 10, Torino (10122) 26 di 28 P.Iva 10669790015 www.corley.it
  • 27. Online updates (2) Corley S.r.l. Piazza Statuto 10, Torino (10122) 27 di 28 P.Iva 10669790015 www.corley.it
  • 28. THANK YOU FOR LISTENING Walter Dal Mut walterdalmut.com - walter.dalmut@corley.it -@walterdalmut Cascina Roccafranca – Torino – 16 giugno 2012 28 di 28