使用 PHPStorm 或 POSTman 的 XDebug 和 RESTful 服务器 [英] XDebug and RESTful server using PHPStorm or POSTman

查看:34
本文介绍了使用 PHPStorm 或 POSTman 的 XDebug 和 RESTful 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得 REST 客户端(例如内置于 PHPStorm邮递员) 使用 XDebug?

How can I get a REST client (such as the one built into PHPStorm or POSTman) to work with XDebug?

在我当前的 XDebug 设置中,使用 PHPStorm 和 提供书签我可以在 Chrome 和 Firefox 中使用它 - 但是一旦我尝试使用 POSTman 或任何其他 REST 客户端,我就无法弄清楚如何开始.

In my current set-up of XDebug, using PHPStorm and the Bookmarklet provided I'm able to get it working in both Chrome and Firefox - but as soon as I try with POSTman or any other REST client, I can't figure out how to get it started.

干杯.

推荐答案

您可以使用以下方法之一:

You can use one of these approaches:

  1. 配置您的 Xdebug(通过编辑 php.ini)以尝试调试 每个 php 脚本.关键选项:

  1. Configure your Xdebug (by editing php.ini) to attempt to debug every php script. The key option:

  • Xdebug v2:xdebug.remote_autostart = 1
  • Xdebug v3:xdebug.start_with_request = yes

将 Xdebug 会话开始参数添加到实际 URL (XDEBUG_SESSION_START={{KEY}} -- http://xdebug.org/docs/remote ),例如:?XDEBUG_SESSION_START=PHPSTORM

Add Xdebug session start parameter to the actual URL (XDEBUG_SESSION_START={{KEY}} -- http://xdebug.org/docs/remote ), for example: ?XDEBUG_SESSION_START=PHPSTORM

将 Xdebug cookie 作为标头之一(由 bookmarklet 或浏览器扩展,例如).

Pass Xdebug cookie as one of the headers (the one which is set by bookmarklet or browser extension, for example).

要使其正常工作:确保电话手柄"已打开.图标在PhpStorm中提前激活(Run | Start Listen for PHP Debug Connection).

For this to work: make sure that "phone handle" icon is activated in advance in PhpStorm (Run | Start Listen for PHP Debug Connection).

PS 如果您使用的是 PostmanInsominia 或类似情况(另一个 REST 客户端),那么 IMO 最好/最透明的方式是使用 Xdebug cookie.您很可能已经在使用单独的环境(例如开发"、测试"、生产"),因此您可以仅在需要的地方使用此类 cookie(当然取决于使用的工具和版本).

P.S. If you are using Postman, Insominia or alike (another REST client) then the best / most transparent way IMO is to use Xdebug cookie. You're most likely already using separate Environments (e.g. "dev", "test", "production") so you can have such cookie only where it is needed (depends on the tool and version used of course).

这样就不需要编辑 URL(即使您将它作为条件参数":在某些环境中存在而在另一种环境中不存在)或将 Xdebug 配置为调试所有请求".完全没有.

This way there is no need to edit the URL (even if you have it as a "conditional parameter": present for some environment and absent for another) or configure Xdebug to "debug all requests" at all.

来自我的 Postman 的此类 Xdebug cookie 的示例(根据需要对其进行编辑;此处为本地 some-domain.local.test 假域设置):

An example of such Xdebug cookie from my Postman (edit it as needed; here it is set for the local some-domain.local.test fake domain):

XDEBUG_SESSION=value; Path=/; Domain=.some-domain.local.test; Expires=Tue, 19 Jan 2038 03:14:07 GMT;

由于主机 URL 应该是您环境的一部分(例如端点 URL 将类似于 {{host}}/api/v1/welcome),那么此类 cookie 将被发送到开发人员仅域而不是生产域.

Since the host URL should be a part of your Environment (e.g. the endpoint URL will be like {{host}}/api/v1/welcome) then such cookie will be sent to the dev domain only and not to the production one.

这篇关于使用 PHPStorm 或 POSTman 的 XDebug 和 RESTful 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆