PHP调试 - 在哪里设置断点?如何验证?

时间:2023-01-18 09:13:17

So I've just recently made the step from ad hoc debugging with dump, print_r and echo to some more sophisticated methods and I'm having a struggle.

所以我最近刚刚从dump,print_r和echo的临时调试到一些更复杂的方法,我正在努力。

I work with Zend Framework, Aptana and Zend Debugger.

我使用Zend Framework,Aptana和Zend Debugger。

At this moment I'm trying to debug a custom controller and whatever I try I don't get to my breakpoint which I understand since there is authentication in between and using the menu.

此刻我正在尝试调试自定义控制器,无论我尝试什么,我都没有达到我理解的断点,因为中间有身份验证并使用菜单。

Questions:

问题:

  1. How can I make my application break at the point of authentication, login in the browser, navigate to a certain uri and then continue debugging?
  2. 如何让我的应用程序在身份验证时中断,在浏览器中登录,导航到某个uri然后继续调试?
  3. What are good places to set breakpoints in Zend Framework with MVC?
  4. 使用MVC在Zend Framework中设置断点的好地方是什么?

4 个解决方案

#1


1  

You want to change the current user's authentication details mid-way through a request?

您想在请求中途更改当前用户的身份验证详细信息吗?

I don't think this is possible. Zend Debugger is pretty much a read-only tool. Even if it were, you're assuming that whatever framework you're using can handle this. That would mean it would have to constantly try to synchronize it's internal state with changing input data.

我不认为这是可能的。 Zend Debugger几乎是一个只读工具。即使它是,你假设你正在使用的任何框架都可以处理这个问题。这意味着它必须不断尝试将其内部状态与不断变化的输入数据同步。

I think instead of asking us how to solve this specific problem, you should be telling us why you need to change authentication. It sounds like you're launching a script in your debugger, which fails because you have no user session.

我认为不应该问我们如何解决这个具体问题,而应该告诉我们为什么需要更改身份验证。听起来你在调试器中启动了一个脚本,因为你没有用户会话而失败了。

Zend Debugger has a browser toolbar (http://files.zend.com/help/Zend-Studio-Eclipse-Help/zend_debugger_toolbar.htm) that allows you to start a the debugger for your current page; the debugger will have all information that the browser would have sent: cookies, post data, etc. There's even a "debug next page" setting which helps you debug POST forms. It sounds like this is what you want.

Zend Debugger有一个浏览器工具栏(http://files.zend.com/help/Zend-Studio-Eclipse-Help/zend_debugger_toolbar.htm),它允许您为当前页面启动调试器;调试器将拥有浏览器发送的所有信息:cookie,发布数据等。甚至还有一个“调试下一页”设置可以帮助您调试POST表单。听起来这就是你想要的。

#2


1  

Wouldn't it be easier to set up a constant such as:

设置常量不是更容易,例如:

define('MODE_DEBUG', 1);

Then check in the authentication process:

然后检查身份验证过程:

if($obj->myLoginMethod() || constant('MODE_DEBUG') == 1){

}

Noone will be able to inject into that constant and the worst thing that can happen is you end up leaving debug mode on my mistake...

没有人能够注入那个常数,最糟糕的事情就是你最终在我的错误上留下调试模式......

Which you could put a check before the definition:

您可以在定义之前进行检查:

define('MODE_DEBUG', (false !== strpos($_SERVER['HTTP_HOST'], 'dev.mysite.com') ? 1 : 0));

#3


1  

Maybe you just need to rethink the dump solution (I like the idea of using breakpoints but turned back after hiccups like your experienced and I use Zend Studio). To debug my applications I make use of Zend_Log and the firebug writer for Zend_Log. The firebug outputs the log to firebug (NB you must have the firephp extension for firefox installed as well). Store the logger in your registry and you can accomplish a lot of debugging without messing up your views with ugly dumps.

也许您只需要重新考虑转储解决方案(我喜欢使用断点的想法,但在经历过像我们经验丰富的打嗝之后又回过头来使用Zend Studio)。为了调试我的应用程序,我使用了Zend_Log和Zend_Log的firebug编写器。 firebug将日志输出到firebug(注意,你必须安装firefox的firephp扩展名)。将记录器存储在注册表中,您可以完成大量调试,而不会使用丑陋的转储来破坏您的视图。

#4


0  

Ok so I played with zend debugger some more. (your question stirred up old demons) and I finally figured out the "proper" way to debug. To answer your initial question to debug after login I would say install the zend toolbar for firefox or IE. To the right of the Debug menu item there is a drop down with some options. One of the options is "next page". So you can go to your login screen select "Next Page" and then put in your credentials and submit and the NEXT page is what is debugged.

好的,所以我更多地使用zend调试器。 (你的问题激起了老恶魔)我最终想出了“适当”的调试方式。要在登录后回答您的初始问题以进行调试,我会说安装firefox或IE的zend工具栏。在Debug菜单项的右侧有一个下拉列表,其中包含一些选项。其中一个选项是“下一页”。因此,您可以转到登录屏幕,选择“下一页”,然后输入您的凭据并提交,NEXT页面就是调试的内容。

#1


1  

You want to change the current user's authentication details mid-way through a request?

您想在请求中途更改当前用户的身份验证详细信息吗?

I don't think this is possible. Zend Debugger is pretty much a read-only tool. Even if it were, you're assuming that whatever framework you're using can handle this. That would mean it would have to constantly try to synchronize it's internal state with changing input data.

我不认为这是可能的。 Zend Debugger几乎是一个只读工具。即使它是,你假设你正在使用的任何框架都可以处理这个问题。这意味着它必须不断尝试将其内部状态与不断变化的输入数据同步。

I think instead of asking us how to solve this specific problem, you should be telling us why you need to change authentication. It sounds like you're launching a script in your debugger, which fails because you have no user session.

我认为不应该问我们如何解决这个具体问题,而应该告诉我们为什么需要更改身份验证。听起来你在调试器中启动了一个脚本,因为你没有用户会话而失败了。

Zend Debugger has a browser toolbar (http://files.zend.com/help/Zend-Studio-Eclipse-Help/zend_debugger_toolbar.htm) that allows you to start a the debugger for your current page; the debugger will have all information that the browser would have sent: cookies, post data, etc. There's even a "debug next page" setting which helps you debug POST forms. It sounds like this is what you want.

Zend Debugger有一个浏览器工具栏(http://files.zend.com/help/Zend-Studio-Eclipse-Help/zend_debugger_toolbar.htm),它允许您为当前页面启动调试器;调试器将拥有浏览器发送的所有信息:cookie,发布数据等。甚至还有一个“调试下一页”设置可以帮助您调试POST表单。听起来这就是你想要的。

#2


1  

Wouldn't it be easier to set up a constant such as:

设置常量不是更容易,例如:

define('MODE_DEBUG', 1);

Then check in the authentication process:

然后检查身份验证过程:

if($obj->myLoginMethod() || constant('MODE_DEBUG') == 1){

}

Noone will be able to inject into that constant and the worst thing that can happen is you end up leaving debug mode on my mistake...

没有人能够注入那个常数,最糟糕的事情就是你最终在我的错误上留下调试模式......

Which you could put a check before the definition:

您可以在定义之前进行检查:

define('MODE_DEBUG', (false !== strpos($_SERVER['HTTP_HOST'], 'dev.mysite.com') ? 1 : 0));

#3


1  

Maybe you just need to rethink the dump solution (I like the idea of using breakpoints but turned back after hiccups like your experienced and I use Zend Studio). To debug my applications I make use of Zend_Log and the firebug writer for Zend_Log. The firebug outputs the log to firebug (NB you must have the firephp extension for firefox installed as well). Store the logger in your registry and you can accomplish a lot of debugging without messing up your views with ugly dumps.

也许您只需要重新考虑转储解决方案(我喜欢使用断点的想法,但在经历过像我们经验丰富的打嗝之后又回过头来使用Zend Studio)。为了调试我的应用程序,我使用了Zend_Log和Zend_Log的firebug编写器。 firebug将日志输出到firebug(注意,你必须安装firefox的firephp扩展名)。将记录器存储在注册表中,您可以完成大量调试,而不会使用丑陋的转储来破坏您的视图。

#4


0  

Ok so I played with zend debugger some more. (your question stirred up old demons) and I finally figured out the "proper" way to debug. To answer your initial question to debug after login I would say install the zend toolbar for firefox or IE. To the right of the Debug menu item there is a drop down with some options. One of the options is "next page". So you can go to your login screen select "Next Page" and then put in your credentials and submit and the NEXT page is what is debugged.

好的,所以我更多地使用zend调试器。 (你的问题激起了老恶魔)我最终想出了“适当”的调试方式。要在登录后回答您的初始问题以进行调试,我会说安装firefox或IE的zend工具栏。在Debug菜单项的右侧有一个下拉列表,其中包含一些选项。其中一个选项是“下一页”。因此,您可以转到登录屏幕,选择“下一页”,然后输入您的凭据并提交,NEXT页面就是调试的内容。