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 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择
  • ¥15 这款软件是什么?需要能满足我的需求
  • ¥15 SpringSecurityOauth2登陆前后request不一致