hogni89
hogni89

Reputation: 1754

Debugging PHP code on a hosted server

I have a hosted server (rochenhost.com), where I run some PHP code. In the old days, before I started working as a software developer, and was self taught I printed the variables out.

Now after some years of school and a developer job, and after I have learned to use debuggers, I wounder: Are there any good debugging tools for PHP code, running on a hosted server?

Upvotes: 1

Views: 2454

Answers (2)

octern
octern

Reputation: 4868

Is the "hosted code" you're working on directly on your production server? Or do you have two separate codebases, one for development (debugging and such) and another for production (displaying to your actual users)? As you probably know, changing code directly on your production server is kind of insane and is almost guaranteed to occasionally bring your site down or create security holes. So my biggest piece of advice would be to get a local development server. This can be as easy as downloading the appropriate XAMP stack for your computer and using your favorite VCS to sync files with the production server once you've debugged them.

Once you have a local development server, check out this question for a list of debuggers with step-through functionality and also this one for a larger list of IDEs available on different platforms.

If you are stuck debugging code on a remote server, here are a couple of other practices that can help. You may already be doing them.

1) Turn on error output. You can do this for a particular script by inserting the following lines at the beginning:

ini_set("display_errors","1");
error_reporting(E-ALL);

This will print (sometimes) informative error messages to the page. It is considered a major security risk to expose this information to visitors, so make sure you remove these lines when you're done testing. If you have a local development server or one that's not accessible to the outside world, you can turn on error reporting for all pages by adding the line display errors = 1 to php.ini.

2) Locate your server's PHP error log. This often contains information about why a page died, even when you're not able to load enough of the page for PHP to display error messages there. You can also use the command error_log('your message here') to print a message to the log, which is useful when you can't just dump the info on your page.

Upvotes: 5

Ryan Fiorini
Ryan Fiorini

Reputation: 800

I use the FirePHP extension for FireFox and ChromePhp for Chrome. They put log messages in the console log of the browsers. They have save me hours of debugging time.

Upvotes: 3

Related Questions