How To Debug Php Scripts

windows

Guest
I need some guidance on debugging PHP scripts. I am fairly new to PHP. I'm trying to modify a fairly large PHP application and I've reached a point where I can't work out what the existing code is doing. Is there some way of inserting something into the script which will print out a call or stack trace of the functions (and maybe parameters) which have got me to this point?<br />What PHP debugging tools are available? I see that there are things like "Advanced PHP Debugger" - are any of these installed by default on TCH? If not, can I install one just for my account?<br />Where do I find more information?<br />Many thanks - Rowan<!--content-->
Hi Rowan. I doubt if any of the debuggers can be user-installed into your account only -- you'd probably need shell access to do that and that is not offered here.<br /><br />One thing you could do perhaps is to load a php interpreter on your computer at home and debug the script there if your script will run that way.<br /><br />If the part of the script you are having trouble with is not too big then you can probably post it here and some of our PHP expert family members may be able to help too.<br /><br />I'm also moving this thread to the Scripting Talk forum so it will get better exposure among the script guys.<!--content-->
Welcome to the forums, Rowan! <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/thumbup1.gif" style="vertical-align:middle" emoid=":thumbup1:" border="0" alt="thumbup1.gif" /> <br /><br />The "Advanced PHP Debugger" (APD) is not available on TCH servers, nor is it something that you can install locally on your account. It requires root access to install, and it may or may not be compatible with other Zend Extensions installed on the server (such as Zend Optimizer, which is installed on TCH servers).<br /><br />You might want to try adding <!--fonto:Courier--><span style="font-family:Courier"><!--/fonto--><!--coloro:blue--><span style="color:blue"><!--/coloro-->var_dump(<a href="http://www.php.net/manual/en/function.debug-backtrace.php" target="_blank">debug_backtrace()</a>);<!--colorc--></span><!--/colorc--><!--fontc--></span><!--/fontc--> to your script at whatever point you're wanting to see a trace.<!--content-->
Welcome to the forums Rowan<br /><br />You can also test your PHP on your own machine if you download <a href="http://www.apachefriends.org/en/xampp.html" target="_blank">XAMMP</a>. It will also run from a USB thumb drive.<!--content-->
Welcome to the forums Rowan<!--content-->
Rowan, if you're modifying a fairly large application, I'll assume you're doing it because you've been put in charge of modifying one of your company's web applications - if that's the case (heck, even if you're working on your own), I seriously suggest you (your company) spend the money on Zend Studio. The debugger and profiler alone are really worth the money.<!--content-->
Welcome to the forums sylvest!<!--content-->
<!--quoteo(post=157288:date=Dec 1 2005, 03:32 PM:name=TCH-David)--><div class='quotetop'>QUOTE(TCH-David @ Dec 1 2005, 03:32 PM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=157288"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->Welcome to the forums, Rowan! <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/thumbup1.gif" style="vertical-align:middle" emoid=":thumbup1:" border="0" alt="thumbup1.gif" /> <br /><br />You might want to try adding <!--fonto:Courier--><span style="font-family:Courier"><!--/fonto--><!--coloro:blue--><span style="color:blue"><!--/coloro-->var_dump(<a href="http://www.php.net/manual/en/function.debug-backtrace.php" target="_blank">debug_backtrace()</a>);<!--colorc--></span><!--/colorc--><!--fontc--></span><!--/fontc--> to your script at whatever point you're wanting to see a trace.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />Thanks to everyone who has replied with useful advice. I will try debug_backtrace, which may help me with my current problem. I wasn't aware of this function.<br /><br />I can see the sense of trying to debug this stuff on a local server before up-loading it, but to be a worthwhile test/debug environment I guess I'd have to have the same or similar versions and configurations of PHP, MySQL, Zend and maybe lots of other things which are running on TCH, and that's gonna take me a long time to learn. I was hoping that I'd be able to debug it running "for real" on TCH, and in fact I've made quite a lot of progress before running into my current problem.<br /><br />Are there any other tools or functions (in addition to debug_backtrace) that I ought to know about which can help in debugging PHP code without root access? Or any tutorials or white papers on this?<br /><br />Thanks all for your help.<br /><br />Rowan<!--content-->
Dont forget you can always use the 'print' function to output to the screen to step through loops and make sure code is running where it is supposed to. <br /><br />I don't waste my time on the expensive and confusing debuggers, maybe because I learned without WYSIWYG and I fix without it <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><!--content-->
Sarah, I'm also a hand-coder myself but believe me, there are times when a debugger will save you a bunch of hours, if not your life! <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" /><!--content-->
<!--quoteo(post=157337:date=Dec 1 2005, 11:37 PM:name=sylvest)--><div class='quotetop'>QUOTE(sylvest @ Dec 1 2005, 11:37 PM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=157337"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->I will try debug_backtrace, which may help me with my current problem.<!--QuoteEnd--></div><!--QuoteEEnd--><br />I've tried this now. It gives me details of the <b><i>current</i> </b>function (i.e. the function inside which I've put the debug_backtrace() call), along with the values of the parameters, but I already know all of that (by putting print statements at appropriate places in the function). It didn't show me what I really wanted to know, which is where is this function called from on each invocation. Does anyone know why not?<br /><br />I found another useful-looking function, debug_print_backtrace(), but this does not seem to be implemented in the version of PHP that tch is running <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" />.<br /><br />Any other ideas???<br /><br />Thanks - Rowan<!--content-->
<!--quoteo(post=157444:date=Dec 2 2005, 11:40 PM:name=sylvest)--><div class='quotetop'>QUOTE(sylvest @ Dec 2 2005, 11:40 PM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=157444"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->It didn't show me what I really wanted to know, which is where is this function called from on each invocation.<!--QuoteEnd--></div><!--QuoteEEnd--><br />Now I realise that I wan't reading the response right. There was only one function in the backtrace because I was only one function deep, and it <b><i>did </i></b>show me the file and line number the function was called from. So I can now make some progress <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/no2.gif" style="vertical-align:middle" emoid=":no2:" border="0" alt="no2.gif" /> <br /><br />Thanks - Rowan<!--content-->
 
Back
Top