我真的很喜欢使用php built in server,我非常喜欢phpdbg的外观。它让我想起了Ruby领域的pry。但我一直无法让它发挥作用。是否可以在Web服务器中使用内置版本运行用户phpdbg
?
,例如,我喜欢这个如何工作:
phpdbg_break();
放入代码 php -S localhost:8000
phpdbg_break();
的代码的请求或通过curl 当我尝试这个时,我收到phpdbg_break();
未定义函数的错误。
或者(如果上述情况不可能),你如何使用“webmocking”that the docs talk about(在底部)?如何使用特定URI发出特定请求?
答案 0 :(得分:6)
If I understand properly, phpdbg_break
is a function provided by the interpreter, and not by any extension. Instead of using the built-in PHP server, you should use the phpdbg server, and simulate a web request. See http://phpdbg.com/docs/mocking-webserver for information on how to mock the request and http://phpdbg.com/docs/simples to know how to run the debugger.
To make a request to the specific URI, I think you need to set $_SERVER['REQUEST_URI']
and optionally $_SERVER['QUERY_STRING']
to point to the URL you want to test. URI will be something like '/path/to/file' and the querystring would be everything between the ? and the # in the URLs (ie ?page=2)
Thanks for pointing me to phpdbg, I didn't know that tool and it seems to be a very good one; I'll be testing it in the next days.
答案 1 :(得分:0)
我出于同样的原因使用psysh,只是因为它让我想起了pry
。实际上,我使用这段代码代替binding.pry
中的ruby
。
require "path_to_psysh_on_your_local_file_system";
\Psy\Shell::debug(get_defined_vars(), $this);
这对我来说已经足够了。我唯一的问题是:
CGI
中运行的现有PHP进程除此之外,我对目前的工作流程感到满意。我很高兴听到其他人的意见。
甚至看起来有关Remote Debugging的一些工作正在进行,这可能会解决我的问题。