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 mainta...
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...
log_errors = On
Write/log errors into a server side
log file; defined by “error_log”
It is strongly recommended to turn
log_...
error_reporting = E_ALL
What type of errors, notices, warnings need
to be notified/write by the php interpreter.
Default va...
Error directives... All at once
php.ini directive default value Purpose Example recommendations
display_errors On
Print ou...
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 ...
Controlling php error reporting
from apache(cont...)
[+] Add the below lines in httpd.conf file:
the integer value 2039 sta...
Setting the error directives at
runtime from the php scripts
It won’t affect if script has fatal errors cause
it might not...
For variable debugging, use reusable method
var_debug($dataNodes,true);
function var_debug( $item, $exit=false )
{
$op = '...
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 deb...
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...
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 corre...
Installing Xdebug(By
Downloading)
Activestate site has binary packages
available for all versions of php in all
platforms(...
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...
Xdebug in action!
restart apache and you’re done!!
xdebug now replaces traditional error messages
with more helpful debug ...
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...
xdebug: Code Coverage
xdebug_start_code_coverage();
var_dump( xdebug_get_code_coverage);
xdebug_stop_code_coverage();
Tell...
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
xdebu...
Powerful code profiling with Xdebug
Sunday, November 7, 2010
Powerful code profiling with Xdebug
(Contd...)
WinCacheGrind: for windows
kCacheGrind: for linux
Webgrind: for all platform...
References
http://www.xdebug.org
http://www.xdebug.org/docs.php
xdebug slides: http://derickrethans.nl/talks.php
http://ww...
who am i
murshed ahmmad Khan
software engineer, somewhere in...
also a bug hunter, code ninja
stay tuned for the updated s...
Thanks!
No Questions?! :)
Sunday, November 7, 2010
Upcoming SlideShare
Loading in …5
×

Even better debugging; Equipped yourself with powerful tools.

2,087 views
2,044 views

Published on

This slide was prepared for the phpxperts seminar 2010. As the presentation time was limited so it only touches few primitive approaches and moves to a mighty debugging extension xdebug. The tag line is "Every job has a unique tool", so spend some time to enrich yourself with powerful debug tools rather than coding all of the time which in turns will save your lot of development time in the future.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,087
On SlideShare
0
From Embeds
0
Number of Embeds
978
Actions
Shares
0
Downloads
41
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Even better debugging; Equipped yourself with powerful tools.

  1. 1. Even Better Debugging Equipped yourself with powerful debug tools Murshed Ahmmad Khan Sunday, November 7, 2010
  2. 2. presented at phpxperts seminar 2010 6th November, 2010 Sunday, November 7, 2010
  3. 3. “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
  4. 4. Frustrating!! blank pages? Think!! what does a blank page mean? What happened? Sunday, November 7, 2010
  5. 5. Let’s have a quick recap of the available error settings in PHP Sunday, November 7, 2010
  6. 6. 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
  7. 7. 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
  8. 8. 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
  9. 9. 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
  10. 10. Revisiting the blank page... TextText browser o/p Sunday, November 7, 2010
  11. 11. Revisiting the blank page... erroneous script server error log Sunday, November 7, 2010
  12. 12. 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
  13. 13. 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
  14. 14. 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
  15. 15. 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
  16. 16. Don’t code all of the time! Rather equipped yourself with powerful tools!! Sunday, November 7, 2010
  17. 17. Xdebug Sunday, November 7, 2010
  18. 18. 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
  19. 19. Xdebug features stack traces infinite recursion protection colored var_dump() function traces Sunday, November 7, 2010
  20. 20. Xdebug features(Cont...) code coverage reports profiling / performance analysis remote debugging a whole lot other features Sunday, November 7, 2010
  21. 21. Installing Xdebug [by PEAR/ PECL] # pecl install xdebug As easy as one command! Sunday, November 7, 2010
  22. 22. 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
  23. 23. 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
  24. 24. Download Xdebug binaries (cont...) http://code.activestate.com/komodo/ remotedebugging/ Sunday, November 7, 2010
  25. 25. Download xDebug...(Grab the extension as per your PHP version Sunday, November 7, 2010
  26. 26. 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
  27. 27. Xdebug in action! restart apache and you’re done!! xdebug now replaces traditional error messages with more helpful debug information. Sunday, November 7, 2010
  28. 28. Xdebug: Stack Traces Sunday, November 7, 2010
  29. 29. Debug Request Variables Xdebug.dump.GET = * Sunday, November 7, 2010
  30. 30. Debug Request Variables Xdebug.dump.GET = * Xdebug.dump.POST = * Also for: COOKIE, ENV, FILES, REQUEST, SERVER and SESSION Sunday, November 7, 2010
  31. 31. 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
  32. 32. Code Coverage(Contd...) Sunday, November 7, 2010
  33. 33. 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
  34. 34. Powerful code profiling with Xdebug Sunday, November 7, 2010
  35. 35. 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
  36. 36. 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
  37. 37. 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
  38. 38. Thanks! No Questions?! :) Sunday, November 7, 2010

×