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.
 
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

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
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 CVKhem
 
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 DevelopmentsTrustArc
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
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...Drew Madelung
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 

Recently uploaded (20)

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 

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