View
1.923
Download
0
Category
Tags:
Preview:
DESCRIPTION
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.
Citation preview
Even Better DebuggingEquipped 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 = OnThis 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 = OnWrite/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 oncephp.ini directive default value Purpose Example recommendations
display_errors OnPrint out errors as part of the
outputdisplay_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 featuresstack 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 VariablesXdebug.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
Referenceshttp://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 imurshed ahmmad Khansoftware engineer, somewhere in... also a bug hunter, code ninja
stay tuned for the updated slides at: http://www.usamurai.comtwitter: @usamurai. email: usamurai@gmail.com
Sunday, November 7, 2010
Thanks!
No Questions?! :)
Sunday, November 7, 2010
Recommended