Best tools for debugging PHP

27 replies
As PHP is a server side language I'm just wondering is there any way to be able to step through line by line a running PHP program? I'm so used to being able to step through line by line with a programming language like Java, it would be fantastic if it were possible to do this with PHP.

Any other tips for general testing of PHP code?
#debugging #php #tools
  • Profile picture of the author GMF1
    I know that the IDE NetBeans can debug PHP code. They even have a tutorial on their site.
    Code:
    netbeans.org/kb/docs/php/debugging.html
    I bet other IDEs like Eclipse can also debug code.
    {{ DiscussionBoard.errors[6623482].message }}
  • Profile picture of the author Sodaware
    I'm a fan of Xdebug (Xdebug - Debugger and Profiler Tool for PHP). It makes debugging things much easier, and also integrates with IDE's to provide line by line step throughs. The profiling features are also top notch.
    {{ DiscussionBoard.errors[6623498].message }}
  • Profile picture of the author Byron Stuart
    Thanks for the suggestions, from looking at netbeans.org/kb/docs/php/debugging.html NetBeans actually needs XDebug to provide line by line debugging. As I am already familiar with NetBeans I will incorporate both of your suggestions :-)
    {{ DiscussionBoard.errors[6623536].message }}
  • Profile picture of the author ALicenseToCode
    Dreamweaver CS5 also has an excellent debugger built in straight out of the box, it highlights all the errors for you and tells you what they are. Although after you've been coding for a year or two you will start just seeing the errors through your supreme nerd-o-vision like I do lol.
    {{ DiscussionBoard.errors[6625671].message }}
  • Profile picture of the author jicon
    I have little knowledge about php but You can use the Xdebug extension, and Eclipse PDT as IDE : the second one is able to use the first one as debugger.
    {{ DiscussionBoard.errors[6638582].message }}
  • Profile picture of the author TopicSpan
    Just wanted to second/third/fourth the XDebug comment. It really is an amazing tool.

    Also bear in mind that you can often do things like this to establish what's gone wrong:

    Code:
    echo print_r(somevariable);
    exit;
    (sorry, code tags don't like the $ symbol!)

    Throw that slap bang in the middle of your code where you think the problem is, and it'll die during the request, neatly spitting out a human-readable form of a variable, object, or array. That may be a little faster than waiting for something to break
    Signature
    Don't lose users!
    Grab our full-page UltraCache system that instantly speeds up any PHP website!
    {{ DiscussionBoard.errors[6639463].message }}
    • Profile picture of the author anconsoft
      Originally Posted by TopicSpan View Post

      Just wanted to second/third/fourth the XDebug comment. It really is an amazing tool.

      Also bear in mind that you can often do things like this to establish what's gone wrong:

      Code:
      echo print_r(somevariable);
      exit;
      (sorry, code tags don't like the $ symbol!)

      Throw that slap bang in the middle of your code where you think the problem is, and it'll die during the request, neatly spitting out a human-readable form of a variable, object, or array. That may be a little faster than waiting for something to break
      You could add something like this to have the results clearer:

      Code:
      echo "<pre>";
      print_r(somevariable);
      echo "</pre>";
      exit;
      Also, Netbeans rules at debugging.
      {{ DiscussionBoard.errors[6700737].message }}
  • Profile picture of the author teguhyuliantos
    Here list of debugging tools for PHP, among of them are :

    1. webgrind
    2. xdebug
    3. gubed PHP
    4. DBG
    5. PHP debug
    6. PHP dyn
    7. etc

    You can try above PHP tools as you wish.
    {{ DiscussionBoard.errors[6641963].message }}
    • Profile picture of the author oknoorap
      Originally Posted by teguhyuliantos View Post

      Here list of debugging tools for PHP, among of them are :

      1. webgrind
      2. xdebug
      3. gubed PHP
      4. DBG
      5. PHP debug
      6. PHP dyn
      7. etc

      You can try above PHP tools as you wish.
      Agree with you sir, I'm using wamp server for localhost, webgrind and xdebug is very help me a lot. But don't forget to clear /tmp folder inside wamp directory.

      Recently I was deleted about 70GB files in /tmp directory.
      {{ DiscussionBoard.errors[6670296].message }}
  • Profile picture of the author jaasmit
    No confusion!!!
    Netbean is the one. That is very easy to use and enriched with so many features.
    So my vote is for netbean.
    {{ DiscussionBoard.errors[6659062].message }}
  • Profile picture of the author cutegirl36
    Hello friv. You should enable error_reporting
    Php code: error_reporting(1);
    Signature

    Source: friv

    {{ DiscussionBoard.errors[6660472].message }}
  • Profile picture of the author mmrumii
    Xdebug, PHP debug and PHP dyn.
    I just know about those. you can try those tools to debug php.
    may be it'll help you out.
    {{ DiscussionBoard.errors[6674385].message }}
  • Profile picture of the author 26medias
    They pretty much listed all the tool.
    I also integrate this function to my code to debug fast:
    function debug($label, $data) {
    echo "<div style=\"margin-left: 40px;\"><u><h3>".$label."</h3></u><pre style=\"border-left:2px solid #000000;margin:10px;padding:4px;\">".print_r($data , true)."</pre></div>";
    }

    use like this:
    debug("any text", $var);
    {{ DiscussionBoard.errors[6676051].message }}
  • I've found the best way to do debugging is by adding catch and debug statements in the code so you know where the code is going and why.
    {{ DiscussionBoard.errors[6677169].message }}
  • Profile picture of the author hitmobi
    I use NetBeans with xDebug .Makes the uncomfortable debugging a breeze.
    {{ DiscussionBoard.errors[6677496].message }}
  • Profile picture of the author augusterber
    Banned
    [DELETED]
    {{ DiscussionBoard.errors[6681091].message }}
    • Profile picture of the author hitmobi
      Originally Posted by augusterber View Post

      Thanks @SolidShellSecurity, I never thought of that, would try that one.
      @hitmobi, you use netbeans with xdebug? how can I do that. Do you integrate xdebug with netbeans? or you run both?
      I think netBeans uses xDebug by default.

      So if you use netBeans and a have a project open - just start debugging. If something is wrong, netBeans will let you know.
      {{ DiscussionBoard.errors[6681951].message }}
      • Profile picture of the author Byron Stuart
        I've looked up the NetBeans documentation in relation to debugging with xDebug and I'm having trouble understanding how exactly these 2 programs integrate.

        The NetBeans debugging page: Debugging PHP Source Code in the NetBeans IDE for PHP Editor provides a link to xDebug stating that it's one of the pieces of software needed. I've downloaded a file called php_xdebug-2.2.1-5.4-vc9-nts-x86_64.dll (I hope it's the right version for me) but where do I put it?

        I see the suggestion by hitmobi that it should just work and he may be right but it seems to me that dll I downloaded should be included and it's definitely not part of NetBeans. I searched the NetBeans directory and xdebug.php is the only file in there with xdebug in the name.
        {{ DiscussionBoard.errors[6693777].message }}
        • Profile picture of the author Brandon Tanner
          Originally Posted by Byron Stuart View Post

          I've looked up the NetBeans documentation in relation to debugging with xDebug and I'm having trouble understanding how exactly these 2 programs integrate.
          If I recall correctly, Xdebug is not actually a part of Netbeans... it's a part of XAMPP. So if you install the full version of XAMPP, then you will have Xdebug. Then it's just a matter of tweaking a few lines in your php.ini file, then you'll be good to go.

          To configure...

          HowToConfigureXDebug - NetBeans Wiki

          To use...

          Debugging PHP Source Code in the NetBeans IDE for PHP Editor
          Signature

          {{ DiscussionBoard.errors[6743364].message }}
  • Profile picture of the author locke815
    Even a Dreamweaver can debug PHP
    {{ DiscussionBoard.errors[6681146].message }}
  • Profile picture of the author stevenh512
    It's been a while since I've done any PHP programming, mostly Rails these days, but I always used Firebug+FirePHP to debug a running app. If you're doing object-oriented PHP (especially using an MVC framework like CodeIgniter) you should also be using a unit testing framework like PHPUnit. Not the same as debugging, but it'll help you find a lot of problems with your code before you deploy it to a live site.
    Signature

    This signature intentionally left blank.

    {{ DiscussionBoard.errors[6681287].message }}
  • Profile picture of the author nobita436
    I am using Dreamweaver to debug PHP script ,but it is not like java editor .You need little knowledge about Dreamweaver,otherwise debugging may be complex to you.
    {{ DiscussionBoard.errors[6696209].message }}
  • Profile picture of the author rising_sun
    Banned
    "notepad++" I am using it right now.
    You can choose "aptana studio",
    but the best tool is "Dreamweaver".
    {{ DiscussionBoard.errors[6699576].message }}
  • Profile picture of the author luckytools
    Xampp is best for development or you may use Wamp but I could recommend you to use Xampp.It's very easy to easy & has lots of features.
    {{ DiscussionBoard.errors[6716820].message }}
  • Profile picture of the author Brennen Noble
    I like Jetbrains PHPStorm alot, bit expensive though...I think it's the best at charting the includes and functions across the filesystem though.
    Signature
    Over 2400 Warriors Use SoreThumb On Their Sites, Do You?
    {{ DiscussionBoard.errors[6745319].message }}
  • Profile picture of the author brianng
    I use Eclipse PHP, and of course, debug options in wordpress/drupal.
    Tried Zend before but I personally felt it's too much. On my second screen: php error logs, apache access, apache error, apache rewrite. That's more than enough =)
    {{ DiscussionBoard.errors[6747470].message }}
    • Profile picture of the author Tavor9
      Call me old fashion but i'm using NotePad++ and checking the logs from my server before going to production..
      {{ DiscussionBoard.errors[6769350].message }}
  • I use Codelobster to debug PHP code.
    It is free and works very well for me.
    {{ DiscussionBoard.errors[11054864].message }}

Trending Topics