views:

59

answers:

3

Hi everyone,

I'm kind of a newbie with PHP so please bear with me. I would like to know if there was an effective way of debugging PHP code so that I don't have to have debugging messages display on the browser.

For example, I find var_dump and print_r functions to be excellent for debugging variables, function calls and arrays respectively. The problem is I have been asked to debug code on a live site (no dev site, I know it is a horrible practice but this is not my project from the start.) So I would like to know what core function or php library or whatever else it is that I could use to log debugging calls in to log that I can check so I don't have to send debugging calls to the browser on a live site?

I like the way you can use the console.log function in JavaScript code and check it in Firebug or the Webkit Console and I also like like the console window in Xcode and I was wondering if there was some similar tool for PHP debugging. Any extra info and pearls of wisdom would be greatly appreciated.

Thanks,

racl101.

+1  A: 

To debug the live site you need to have Zend Debugger extension installed on its server. Its configuration has to allow you to connect to the debugger from your IP address. See this guide from Zend.

Next you will have to use a supported debugger client. Have a look at Zend Studio for Eclipse which is nice, or you can use Eclipse PDT with Zend Debugger plugin.

Once you are setup (client and server) you will be able to set breakpoints in your code and see variables / step through code while running, etc.

Alternative to Zend Debugger is xDebug.

Danila V.
thanks for the tip. I will consider this as a long run solution.
Thanks for your suggestion. It should be the most helpful in the long run.
+1  A: 

If you like Firebug check out FirePHP, its an extension onto Firebug and works similarly http://www.firephp.org/

quick tutorial: http://www.developertutorials.com/blog/php/debugging-php-with-firebug-and-firephp-365/

cdnicoll
As short run solution I think I'll use this FirePHP extension.
A: 

If you just want to write to a log file, there's the function error_log. It'll write to your webserver's error log file (which will vary in location from system to system depending on how the webserver is setup).

ddrown
I wanted something a little more ambitious than the error_log function but it's still a good simple thing to use.