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

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.

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

+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...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

"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 ...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
+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...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 

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