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.
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
5. Let’s have a quick recap of the
available error settings in PHP
Sunday, November 7, 2010
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. 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. 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. 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
11. Revisiting the blank page...
erroneous
script
server error log
Sunday, November 7, 2010
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. 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. 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
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
21. Installing Xdebug [by PEAR/
PECL]
# pecl install xdebug
As easy as one command!
Sunday, November 7, 2010
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
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. Xdebug in action!
restart apache and you’re done!!
xdebug now replaces traditional error messages
with more helpful debug information.
Sunday, November 7, 2010
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
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
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