我想使用PhpStorm 10和xdebug调试php脚本。我的设置如下:
客户端是python。客户端发送json数据。客户端的代码是(contact是包含json的变量):
conn = httplib.HTTPConnection('192.168.2.103:85')
headers = {"Content-type": "application/json", "charset" : "utf-8"}
body = json.dumps(contact, ensure_ascii = 'False')
conn.request('POST', '/web_service/index.php', body, headers)
response = conn.getresponse()
服务器端是php。在服务器端,我将xdebug设置如下:
zend_extension = "E:\_Dizertatie\php\ext\php_xdebug.dll"
xdebug.profiler_enable = 1
xdebug.profiler_output_dir = "E:\_Dizertatie\tmp"
xdebug.remote_enable =true
xdebug.remote_host = "127.0.0.1"
xdebug.remote_port = 9000
使用此guide和此page我只能在启动“启动调试”书签时调试我的页面。我的python请求没有被捕获到PhpStorm的调试器中。我想被动地听(不使用bookmarklets)并在php调试器中捕获所有请求,无论它们的来源(python,mobile,不同的php脚本)。
在发送python请求时,是否有可用于调试php脚本的配置?
答案 0 :(得分:1)
You need to tell xdebug that you want to debug this request.
This is exactly what bookmarkets/browser extensions do -- they set xdebug cookie that is sent together with next page request. You can replace cookie by actual GET or POST parameter via XDEBUG_SESSION_START -- e.g. add such parameter to your conn.request(...
line.
Alternatively you can tell xdebug to debug every single request automatically (via xdebug.remote_autostart = 1
in your php.ini
) which can be undesired and may have some "side effects" (approx 1 sec delay in execution if debug client is not available -- the time xdebug waits for possible client to respond). That's to go with zero config approach (the "phone handle" icon) you are using already.
If you are using this option then do not forget to restart your web server (or php-fpm
if you are using it) after making changes in php.ini. Otherwise it is very unlikely that those changes will be picked up automatically until restart (by default in most setups).
P.S.
PhpStorm has built-in simple REST Client accessible via Tools | Test RESTful Web Service
which you can use to send custom requests (instead of using your real client side (python code in your case)).
Since PhpStorm v11 (will be released soon) you can initiate debug directly from there (dedicated "Debug" button) instead of adding xdebug cookie/query parameters.
Another alternative is to use similar browser-based tool (e.g. Postman for Chrome).