dongxidui1227 2012-04-19 11:14
浏览 32
已采纳

在托管服务器上调试PHP代码

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?

  • 写回答

2条回答 默认 最新

  • du656637962 2012-04-19 18:22
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭