SlideShare uma empresa Scribd logo
1 de 38
Baixar para ler offline
Even Better Debugging
Equipped yourself with powerful debug tools
Murshed Ahmmad Khan
Sunday, November 7, 2010
presented at phpxperts
seminar 2010
6th November, 2010
Sunday, November 7, 2010
“The defect is the crime; debugging is
the punishment”
Cause nobody’s perfect; study says we use 80% of
our time to maintain the old codes.
Sunday, November 7, 2010
Frustrating!! blank pages?
Think!! what does a blank page mean? What happened?
Sunday, November 7, 2010
Let’s have a quick recap of the
available error settings in PHP
Sunday, November 7, 2010
display_errors = On
This determines whether errors should be
printed to the screen as part of the script
output; depending on the error_reporting value.
It is strongly recommended to turn
it “Off” in the production server.
Default value is “On”.
Sunday, November 7, 2010
log_errors = On
Write/log errors into a server side
log file; defined by “error_log”
It is strongly recommended to turn
log_errors “On” in place of display_errors
in the production web sites.
Default value is “Off”.
Sunday, November 7, 2010
error_reporting = E_ALL
What type of errors, notices, warnings need
to be notified/write by the php interpreter.
Default value is E_ALL & ~ E_NOTICE
When developing best practice is to use
E_ALL. Or even better E_ALL | E_STRICT.
Sunday, November 7, 2010
Error directives... All at once
php.ini directive default value Purpose Example recommendations
display_errors On
Print out errors
as part of the
output
display_errors = On
strongly
recommended to
turn it off in
production
log_errors Off
log errors into a
log file
log_errors = On
strongly recommended
to turn it on in
production
error_reporting
E_ALL &
~E_NOTICE
what type of
errors need to be
notified and/or
logged
error_reporting =
E_ALL
show all errors except
notices:
E_ALL & ~ E_NOTICE
for development in php5,
show all type of errors:
E_ALL | E_STRICT
*from php6 E_STRICT will
also be included in E_ALL
Sunday, November 7, 2010
Revisiting the blank page...
TextText
browser o/p
Sunday, November 7, 2010
Revisiting the blank page...
erroneous
script
server error log
Sunday, November 7, 2010
Controlling php error reporting
from apache httpd.conf
Sometimes turning error reporting on in
php.ini may not work.
It’s good to know how to set these
configuration variables from server side.
Setting these in httpd.conf file overrides all
php.ini & guarantee to set the error levels.
Sunday, November 7, 2010
Controlling php error reporting
from apache(cont...)
[+] Add the below lines in httpd.conf file:
the integer value 2039 stands for E_ALL &
~E_NOTICE
There are different integer values for each error
types
[+] php_flag display_errors on
[+] php_value error_reporting 2039
Sunday, November 7, 2010
Setting the error directives at
runtime from the php scripts
It won’t affect if script has fatal errors cause
it might not get executed.
ini_set(‘display_errors’, 1);
ini_set(‘error_reporting’, E_ALL);
// error_reporting(E_ALL);
Sunday, November 7, 2010
For variable debugging, use reusable method
var_debug($dataNodes,true);
function var_debug( $item, $exit=false )
{
$op = '<pre>DEBUG INFO</pre>';
$op .= '<pre>' . print_r( $item, true ) . '</pre>';
if( is_production() ){
$op = ‘<!-- ’ . $op . ‘ -->’;
//return false;
}
echo $op;
if( $exit ){ exit(); }
}
Sunday, November 7, 2010
Don’t code all of the time! Rather
equipped yourself with powerful tools!!
Sunday, November 7, 2010
Xdebug
Sunday, November 7, 2010
What is Xdebug?
Xdebug is one of the most popular
debugging engines in PHP
A PHP extension about 8 years old
Uses DBGp debugging protocol
Sunday, November 7, 2010
Xdebug features
stack traces
infinite recursion protection
colored var_dump()
function traces
Sunday, November 7, 2010
Xdebug features(Cont...)
code coverage reports
profiling / performance
analysis
remote debugging
a whole lot other features
Sunday, November 7, 2010
Installing Xdebug [by PEAR/
PECL]
# pecl install xdebug
As easy as one command!
Sunday, November 7, 2010
Installing Xdebug[PEAR/
PECL cont...]
Ignore any prompt: you should add
“extension=xdebug.so” in php.ini
[+] Add the correct line in your php.ini file:
[+] zend_extension = “/usr/local/
php/modules/xdebug.so”
Sunday, November 7, 2010
Installing Xdebug(By
Downloading)
Activestate site has binary packages
available for all versions of php in all
platforms(Windows/MacOSX/Linux)
Sunday, November 7, 2010
Download Xdebug binaries
(cont...)
http://code.activestate.com/komodo/
remotedebugging/
Sunday, November 7, 2010
Download xDebug...(Grab the
extension as per your PHP version
Sunday, November 7, 2010
Xdebug Installation(contd...)
paste the xdebug.so/xdebug.dll file into the
extension directory
[+]Add the extension path in the php.ini
[xdebug]
zend_extension = “/Applications/MAMP/bin/php5/
lib/php/extensions/no-debug-non-zts-20060613/
xdebug.so”
xdebug.file_link_format = “txmt://open?url=file://
%f&line=%1”
Sunday, November 7, 2010
Xdebug in action!
restart apache and you’re done!!
xdebug now replaces traditional error messages
with more helpful debug information.
Sunday, November 7, 2010
Xdebug: Stack Traces
Sunday, November 7, 2010
Debug Request Variables
Xdebug.dump.GET = *
Sunday, November 7, 2010
Debug Request Variables
Xdebug.dump.GET = *
Xdebug.dump.POST = *
Also for: COOKIE, ENV, FILES, REQUEST,
SERVER and SESSION
Sunday, November 7, 2010
xdebug: Code Coverage
xdebug_start_code_coverage();
var_dump( xdebug_get_code_coverage);
xdebug_stop_code_coverage();
Tells you which lines of script have been
executed during the request.
Sunday, November 7, 2010
Code Coverage(Contd...)
Sunday, November 7, 2010
Remote Debugging(step by step
debugging with IDE or any DbGp
interface)
[+] php.ini settings:
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.extended_info=1
Sunday, November 7, 2010
Powerful code profiling with Xdebug
Sunday, November 7, 2010
Powerful code profiling with Xdebug
(Contd...)
WinCacheGrind: for windows
kCacheGrind: for linux
Webgrind: for all platforms
Easy Xdebug: browser extensions
(firefox addon)
Sunday, November 7, 2010
References
http://www.xdebug.org
http://www.xdebug.org/docs.php
xdebug slides: http://derickrethans.nl/talks.php
http://www.devshed.com/c/a/PHP/Error-and-
Exception-Handling-in-PHP/
http://www.php.net/manual/en/debugger-
about.php
Sunday, November 7, 2010
who am i
murshed ahmmad Khan
software engineer, somewhere in...
also a bug hunter, code ninja
stay tuned for the updated slides at:
http://www.usamurai.com
twitter: @usamurai. email: usamurai@gmail.com
Sunday, November 7, 2010
Thanks!
No Questions?! :)
Sunday, November 7, 2010

Mais conteúdo relacionado

Destaque

The Edge- Corporate presentation
The Edge- Corporate presentationThe Edge- Corporate presentation
The Edge- Corporate presentation
Manish Maniyar
 
Working with Microsoft Ribbon
Working with Microsoft RibbonWorking with Microsoft Ribbon
Working with Microsoft Ribbon
vcagwin
 
Touring Solar System Final 2
Touring Solar System Final 2Touring Solar System Final 2
Touring Solar System Final 2
Erin Lewis
 

Destaque (17)

Cuidadano
CuidadanoCuidadano
Cuidadano
 
Best practices in ic communication 2011
Best practices in ic communication   2011Best practices in ic communication   2011
Best practices in ic communication 2011
 
Skyline charts by Bill Caemmerer
Skyline charts by Bill CaemmererSkyline charts by Bill Caemmerer
Skyline charts by Bill Caemmerer
 
The Edge- Corporate presentation
The Edge- Corporate presentationThe Edge- Corporate presentation
The Edge- Corporate presentation
 
Apache Solr! Enterprise Search Solutions at your Fingertips!
Apache Solr! Enterprise Search Solutions at your Fingertips!Apache Solr! Enterprise Search Solutions at your Fingertips!
Apache Solr! Enterprise Search Solutions at your Fingertips!
 
Didáctica aplicada plan simce
Didáctica aplicada plan simceDidáctica aplicada plan simce
Didáctica aplicada plan simce
 
Mars Lesson Presentation
Mars Lesson PresentationMars Lesson Presentation
Mars Lesson Presentation
 
Figuras retóricas clase práctica
Figuras retóricas clase prácticaFiguras retóricas clase práctica
Figuras retóricas clase práctica
 
Life after levels - A Profound Change
Life after levels - A Profound ChangeLife after levels - A Profound Change
Life after levels - A Profound Change
 
World at work conference presentation v1
World at work conference presentation v1World at work conference presentation v1
World at work conference presentation v1
 
Working with Microsoft Ribbon
Working with Microsoft RibbonWorking with Microsoft Ribbon
Working with Microsoft Ribbon
 
Touring Solar System Final 2
Touring Solar System Final 2Touring Solar System Final 2
Touring Solar System Final 2
 
Keeping Employee Motivation Up Kn Article 2 25
Keeping Employee Motivation Up Kn Article 2 25Keeping Employee Motivation Up Kn Article 2 25
Keeping Employee Motivation Up Kn Article 2 25
 
Comprensión de lectura y vocabulario contextual síntesis
Comprensión de lectura y vocabulario contextual síntesisComprensión de lectura y vocabulario contextual síntesis
Comprensión de lectura y vocabulario contextual síntesis
 
Total rewards communication &amp; framework overivew 2015
Total rewards communication &amp; framework overivew 2015Total rewards communication &amp; framework overivew 2015
Total rewards communication &amp; framework overivew 2015
 
Behavioral economics in 22 slides - showing that we are irrational
Behavioral economics in 22 slides - showing that we are irrationalBehavioral economics in 22 slides - showing that we are irrational
Behavioral economics in 22 slides - showing that we are irrational
 
4 Drives A Simple Story About Motivating Employees
4 Drives   A Simple Story About Motivating Employees4 Drives   A Simple Story About Motivating Employees
4 Drives A Simple Story About Motivating Employees
 

Semelhante a Even better debugging; Equipped yourself with powerful tools.

Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
Joshua Warren
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Openmeetings
OpenmeetingsOpenmeetings
Openmeetings
hs1250
 

Semelhante a Even better debugging; Equipped yourself with powerful tools. (20)

Drupal Development w/ PhpStorm and Xdebug
Drupal Development w/ PhpStorm and XdebugDrupal Development w/ PhpStorm and Xdebug
Drupal Development w/ PhpStorm and Xdebug
 
Creating Clean Code with AOP
Creating Clean Code with AOPCreating Clean Code with AOP
Creating Clean Code with AOP
 
Creating Clean Code with AOP
Creating Clean Code with AOPCreating Clean Code with AOP
Creating Clean Code with AOP
 
The why and how of moving to php 7
The why and how of moving to php 7The why and how of moving to php 7
The why and how of moving to php 7
 
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
 
The why and how of moving to php 8
The why and how of moving to php 8The why and how of moving to php 8
The why and how of moving to php 8
 
Php Development Stack
Php Development StackPhp Development Stack
Php Development Stack
 
Php Development Stack
Php Development StackPhp Development Stack
Php Development Stack
 
Summer training report priyanka
Summer  training  report priyankaSummer  training  report priyanka
Summer training report priyanka
 
Install odoo v8 the easiest way on ubuntu debian
Install odoo v8 the easiest way on ubuntu debianInstall odoo v8 the easiest way on ubuntu debian
Install odoo v8 the easiest way on ubuntu debian
 
PHPUnit
PHPUnitPHPUnit
PHPUnit
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Openmeetings
OpenmeetingsOpenmeetings
Openmeetings
 
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven PignataroJoomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
 
Xdebug
XdebugXdebug
Xdebug
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 
Php Debugger
Php DebuggerPhp Debugger
Php Debugger
 
Software Instructions
Software InstructionsSoftware Instructions
Software Instructions
 
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
 

Último

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
panagenda
 
+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
 

Último (20)

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
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
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
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
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
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
 
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...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
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
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
+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...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Even better debugging; Equipped yourself with powerful tools.