简体   繁体   English

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

[英]Debugging PHP code on a hosted server

I have a hosted server (rochenhost.com), where I run some PHP code. 我有一台托管服务器(rochenhost.com),在其中运行一些PHP代码。 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? 现在经过几年的学习和开发工作,当我学会了使用调试器后,我很伤心:在托管服务器上运行的PHP代码是否有良好的调试工具?

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. 这很容易,只要为您的计算机下载适当的XAMP堆栈,并在调试文件后使用喜爱的VCS将文件与生产服务器同步即可。

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. 一旦你有一个本地开发服务器,检查出这个问题的调试器的步骤,通过功能,还列出这一项在不同的平台上可用的IDE的大名单。

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. 1) 打开错误输出。 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. 如果您有本地开发服务器或外界无法访问的服务器,则可以通过向php.ini添加行display errors = 1来打开所有页面的错误报告。

2) Locate your server's PHP error log. 2) 找到您服务器的PHP错误日志。 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. 它通常包含有关页面为何死亡的信息,即使您无法为PHP加载足够的页面显示错误消息的原因。 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. 您还可以使用命令error_log('your message here')将消息打印到日志中,这在您不只是将信息转储到页面上时很有用。

I use the FirePHP extension for FireFox and ChromePhp for Chrome. 我将FirePHP扩展用于FireFox,将ChromePhp用于Chrome。 They put log messages in the console log of the browsers. 他们将日志消息放入浏览器的控制台日志中。 They have save me hours of debugging time. 他们为我节省了数小时的调试时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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