|
Softpanorama
(slightly skeptical)
Open Source Software Educational Society |
May the
source be with you,
but remember the KISS principle ;-)
|
PHP Debugging
PHP does not have built-in debugger and as such is inferior scripting
language to Perl, Python and Ruby.
When push
comes to
shove, the
simple fact
is that most
anyone can
learn the
syntax and
grammar of a
programming
language
well enough
to write
programs.
However, as
applications
and projects
become
larger,
the method
of finding errors provided by the language became as important as the
language itself. PHP sucks in this respect.
The most well know debugger for PHP is DBG debugger. There are several
external tools that are based on DBG debugger. They include
Dev-PHP , Komodo and Eclipse.
Another free PHP debugger is Gubed and
PECL. The latter is a
full-featured profiler/debugger that is loaded as a zend_extension. It aims to
be an analog of C's gprof or Perl's Devel::DProf.
Xdebug is debugger
based of Xdebug protocol. Xdebug 2 is a true multi-language protocol. This means
that a client written for Xdebug 2 will also work in combination with the Perl,
Python, Tcl and XSLT debuggers from Active State. For a description of (a draft)
of this new protocol, see the
documentation - protocol page. The development of the protocol is sponsored
by
Maguma and will also be implemented in Maguma Studio 2.
PSD - A visual frontend for debugging
PHP. It runs on Win98SE and newer and can be used remotely. [Freeware]
Notes:
- This is a Spartan WHYFF (We Help
You For Free) site written by people for whom English
is not a native language.
Some amount of grammar and spelling errors should be
expected.
- The site contain some broken links
as it develops like a living tree...
Please try to use Google, Open directory,
etc. to find a replacement link (see
HOWTO search the WEB for details). We would appreciate
if you can
mail us a correct link.
|
|
|
|
Discover five common database problems that occur in PHP
applications -- including database schema design, database access, and the
business logic code that uses the database -- as well as their solutions.
Explore various methods for debugging PHP applications,
including turning on error reporting in Apache and PHP, and
by placing strategic print statements to locate the source
of more difficult bugs through a simple example PHP script.
The PHPeclipse plug-in for Eclipse, a slick development
environment with real-time syntax parsing abilities, will
also be covered, as well as the DBG debugger extension for
PHPeclipse.
Program checking is not bebugging.
Whether you're a PHP newbie or a wizard, your programs are going to have bugs
in them. Nobody's perfect. This article gives you some techniques for finding and
fixing the problems in your programs. It covers three topics:
- How to get the PHP interpreter to report the errors that interest
you.
- How to locate basic syntax errors in your program.
- How to check the values of variables as your program is running.
Configuring Error Reporting
First of all, you need to configure the PHP interpreter so that when an
error happens, you can see information about it. The error info can be sent along
with program output to the web browser. It can also be included in the web
server error log. A common way to set things up is to have error output go to
the web browser when you're debugging your program, and then to the web server error
log once the program is finished and (supposedly) working properly. That way, web
site users can't see any potentially sensitive data included with error output.
To make error messages display in the browser, set the display_errors
configuration directive to On. To send errors to the
web server error log, set
log_errors to On. You can
set them both to On if you want error messages in both places.
An error message that the PHP interpreter generates falls into one of
five different categories:
- Parse error: A problem with the syntax of your program,
such as leaving a semicolon off of the end of a statement. The interpreter stops
running your program when it encounters a parse error.
- Fatal error: A severe problem with the content of
your program, such as calling a function that hasn't been defined. The interpreter
stops running your program when it encounters a fatal error.
- Warning: An advisory from the interpreter that something
is fishy in your program, but the interpreter can keep going. Using the wrong
number of arguments when you call a function causes a warning.
- Notice: A tip from the PHP interpreter, playing the
role of Miss Manners. For example,
printing a variable without first initializing it to some value generates
a notice.
- Strict notice: An admonishment from the PHP interpreter
about your coding style. Most of these have to do with esoteric features that
changed between PHP 4 and PHP 5, so you're not likely to run into them too much.
You don't have to be notified about all of the different error categories.
The error_reporting configuration directive controls which kinds of
errors the PHP interpreter reports. The default value for error_reporting
is E_ALL & ~E_NOTICE & ~E_STRICT, which tells the interpreter to report
all errors except notices and strict notices.
PHP defines some constants you can use to set the value of error_reporting
so that only errors of certain types get reported: E_ALL (for all errors
except strict notices), E_PARSE (parse errors), E_ERROR
(fatal errors), E_WARNING (warnings), E_NOTICE (notices),
and E_STRICT (strict notices).
Because strict notices are rare (and new to PHP 5), they are not included
in E_ALL. To tell the PHP interpreter that you want to hear about everything
that could possibly be an error, set error_reporting to E_ALL
| E_STRICT.
About the debuggerPHP
3 includes support for a network-based debugger.
PHP 4 does not have an internal debugging facility. You
can use one of the external debuggers though. The
Zend IDE includes a debugger, and there are also some
free debugger extensions like DBG at
http://dd.cron.ru/dbg/, the
Advanced PHP Debugger (APD) or
Xdebug
which even has a compatible debugger interface as PHP 3's
debugging functionality as is described in this section.
13-Sep-2006 09:51
NuSphere Php IDE PhpED (www.nusphere.com)
includes dbg from dd.kron.ru actually
online _ use _ only == hotmail.com
15-Mar-2006 04:41
I still find that printing
out variable values at problem points in the code is
one of the easiest ways for me to debug. If you're
interested in knowing the full contents of an
object/array/scalar, then use
var_dump($var).
joe_fitchnospam at hotmail dot com
17-Dec-2002 01:15
I've tried many debuggers and PHP IDEs
including Zend IDE, Komodo, PHPEdit, PHPEd and
Maguma Studio.
After all I'm sure that the best one debugger is
dbg. It supports breakpoints even conditional ones,
all kind of steps throu php code, watch etc, so it's
a fully functional debugger indeed and profiler too.
Fortunately, it's an open-source product as PHP
itself. Unfortunately, it does not contain any
front-end, but 3rd party PHP IDEs. Seems, as for an
IDE the best one is PHPEd 3.1 (http://www.phped.com),
former PHP IDE from Ergin Soysal.
I was also deeply impressed with IonCube accelerator
performance (http://www.ioncube.com).
Commercial version of IONCUBE is many times faster
than the commercial one from Zend (www.zend.com).
Huh ?
Hope this info would help someone to find the better
way faster.
23-Aug-2002 12:51
check out this great, cross-platform, my
favourite php debugger:
http://www.activestate.com/Products/Komodo/
it not only allows "debugging PHP programs locally
or remotely, including debugging in CGI or other Web
Server API environments", but, besides, is a full
fledged Perl, PHP, Python, Tcl, and XSLT IDE. based
on mozilla.
current version 1.2.9 costs some money ($29.50 non
commercial), previous version 1.1 is free (non
commercial).
In case of broken links
please try to use Google search. If you find the page please notify
us about new location
PHP Command Line Use
PHP has steadily progressed to the stage that command line usage of the PHP.exe
is easier than ever before; especially with the new PHP 5 betas. This is most
fortunate because it makes testing out little scriptlets of PHP code easier
than ever. And with the new OOP and XML capabilities of PHP there are plenty
of opportunities to test PHP fast and easily with command line test scripts
and even simple batch harnesses that rip through 10 variations on a OOP definition
theme. The side benefit ? Users suddenly discover that with regular expressions,
great database connectivity, always great file I/O operations, easy array manipulation
- in short the whole legacy Perl-like and enhanced features, PHP makes a great
OS scripting agent.The figure below shows the command options available when
running PHP in command line mode.
SourceForge.net: PHP debugger DBG
DBG is a full-featured PHP Debugger and Profiler. Makes it easier to find
problems or bugs in PHP scripts. DBG supports back-tracking, watching
variables, viewing arguments passed to all nested function calls at any
point of execution. Opensource.
DBG PHP Debugger and Profiler. -- home
site of DBG debugger
Debugging techniques for PHP programmers
Zend Technologies -
Beginner Tutorials - JavaScript Powered PHP ...
PHP: Debugging PHP - Manual
Komodo 3.1 - Online Docs : Debugging PHP
12 Steps to a Bigger, Better, Debugger evolt.org
Recommended PHP reading list
- "Debugging
techniques for PHP programmers"
- Explore various methods for debugging PHP applications,
including turning on error reporting in Apache and PHP, and
placing strategic print statements to locate the source of
more difficult bugs through a simple example PHP script. The
PHPEclipse plug-in for Eclipse, a slick development
environment with real-time syntax parsing abilities, is also
covered, as is the DBG debugger extension for PHPEclipse.
- "PHP
Performance Profiling"
- Learn how to use the Advanced PHP Debugger (APD) to
profile your PHP code. Code profiling helps you identify
bottlenecks or inefficient code in your application,
enabling you to tune the code where needed.
-
Advanced PHP Debugger
- The Advanced PHP Debugger (APD) is a Zend extension that
provides traces suitable for debugging and profiling code,
as well as full stack backtrace. Events-based logging is
also supported, so different levels of information logging
can be set on a script by script basis.
- Xdebug
- Xdebug is an extension that offers debugging
information, including full traces and function/line
indicators. Xdebug also includes profiling and script
execution analysis.
Last updated:
August 15, 2009