简体   繁体   中英

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM