Xdebug With Postman



最近用postman发起请求,发现本地phpstrom设置的断点无效,很奇怪,百度了一下解决办法很简单,需要开启postman的phpstrom调试功能phpstrom + xdebug+postman第一步:打开postman,右边找到Cookies 点击Cookies, 填入 XDEBUGSESSION=PHPSTORM 则可调起phpstrom的调试功能第二步.

August 05, 2016Foucauld Degeorges6 min read

The following video describes how to debug PHP applications using PHP Xdebug extension and PHPStorm.The video describes this on Windows Xampp installation, b. While filling the details, make sure the setting specified in the php.ini file should match with IDE KEY and click Ok. Open the PHP file you want to debug in the Notepad and add a breakpoint to the script. You will see the Notepad icon blinking on the taskbar. Click on it and start debugging. Xdebug and Postman If you wish to debug a request sent by Postman, all you need to do is add XDEBUGSESSIONSTART=PHPSTORM as a key-value pair to the request body and start the debug config as you would when debugging via Chrome. Free download mac os x lion installer.

Xdebug With Postman

When working on a project with both an API and a frontend, it's more convenient to work on both at the same time, as they can influence one another. I was recently working on an API with a mobile development team, and we lost some valuable time asking each other about the format for a certain request, and retyping the same requests for ten-times-a-day operations such as logging in as our test user.

We were using Postman - which you've most probably heard of it you've worked with or on an API - to run HTTP requests, and keep a history of our past requests. I stopped counting how many times I tried to reuse an obsolete request, got a 4XX-5XX, and thought something was wrong. And one fine morning, I realized that Postman had a Collections tab next to the History tab, and offered cloud storage to save requests and share them with your team.

The whole team sharing thing is a paid feature called Postman Cloud. It costs $5 per active team member per month, with a free 30-day trial period with unlimited users. It offers nice little extras such as auto-generated documentation. In this article, I will walk you through the process of setting up Postman Cloud, keeping and sharing your API requests and documenting your endpoints.

Setup Account and Team

Most Postman users don't have a Postman account because you don't need one to use the app. Assuming you've installed Postman, the first thing to do is to create your account. Fireplace download mac.

Then, subscribe to Postman Cloud or the free trial period from the Pricing page. Then go to the team page and start adding people to your team. If they already have a Postman account, make sure to use the right email.

Once you have your account set up and confirmed, you can launch the app and log in from the top right corner.

You're logged in!

Pro Tip: There is an OSX desktop app (direct download) if you're on a Mac, which solves a strange window switching issue I had with the Chrome app.

Organize your requests into Collections and Environments

The first thing to notice is that you have a Collections tab on the left menu bar. There, you can create a new Collection. This will hold all your requests for a project. When you are logged in, your Collections are automatically uploaded to your account.

The three dots menu next to the Collection allows you to edit it, share it with your team with read or write access and create a subfolder hierarchy inside your Collection.

Create a new request as usual: choose the method, enter the endpoint, the body and any custom headers. Next to the button that executes your request, there is a 'Save' button to save it into a Collection. Give it a meaningful name, choose the collection and possibly a subfolder to save it into, and you’re done! The request is uploaded and shared with the team. They see your Collection just like one of their own (note the self-explanatory 'Me' / 'Team' filter above the Collections list).

Your new Collection

Xdebug With Postman Extension

Now, you probably worked on more than one server. That's where Postman Environments come in.

This feature lets you use variables inside your requests and define multiple Environments with their own value for each variable. Environments can be chosen and managed from the menu next to the eye icon at the top right (in the second row of icons). You can create one or more Environments, in which you set a value for a variable called hostname, and use it in your request URL with double curly braces: https://{{hostname}}/endpoint. Then, before running the request, pick an Environment from the menu and Postman will use the correct value. You can also choose to share an Environment with your team, just like the Collection.

Document and Publish your API

From your Collections page on the Postman website, you can choose to view the documentation for your Collection. This generates a web page which displays your Collection very nicely, with the folder hierarchy, request details and multi-language examples next to one another. On the top right, you can switch between Environments, and the «Run in Postman» button opens the viewer’s Postman app and gives them (readonly) access to your requests so they can try them with one click. Note that for the moment, only the team can see this page.

Looks nice, right?

Here's how to make it even better:

  • Add helpful descriptions to each request. From Postman, in the three-dots menu next to each saved request, you can edit it and add a description. You can also add a description to each subfolder, and to the Collection itself. You can even unleash the full power of Markdown to make those descriptions look better.
  • Give example responses for each request, so that users know what response format(s) to expect. To do this, run your request and get an actual response. Then click 'Save Response' button in the top right corner of the response box, and give it a meaningful name (ex: 'Normal Response' or 'Error Response'). It gets uploaded and shows in the doc just below the request. You can save any number of response per requests.

As you get to production, you can Publish your API reference from your dashboard. If you have multiple Environments, you can choose the one that will be used for the published doc. Publication means that any user with the link can view the documentation, use it and import your Collection to their own Postman using the «Run in Postman» button.

The ultimate example of documented API is the Postman Cloud API itself, which the Postman client uses to sync your Collections. (Yes, it’s an API to store data about APIs :O) As a Postman Cloud user, you can use the 'Run in Postman' button to import the doc into Postman, play with it (get the API key from your dashboard) and see for yourself how they created this full-featured API reference.

Areas for Improvement

Here are a few things I believe are most important for Postman Cloud to improve:

  • Allow response editing: Before I save a response as a sample response for my documentation, I might need to anonymize the data in the response. I need to be able to edit the response before I save it.
  • Clarify teams and organizations: I believe basic team sharing should be free, but as a paid feature I would want to be part of multiple teams within an organization, à la Github.
  • Allow me to self-host the doc: Allow me to download or integrate the documentation into my website, or give me more control over the URL of my documentation, and I would look more professionnal when publicizing the link to my users.
  • Control public doc change: As the team develops the API, some requests may be shared between them, yet not ready for public consumption. We need a way to prevent specific requests from appearing in the doc, or better, only manually update the public documentation when ready to do so.

Xdebug Postman

Bottom Line

I believe Postman Cloud is a tool that can really make your life easier when building an API, especially when front-end development happens simultaneously (which it should). The price tag may seem odd to a user, but a company can easily administrate a team with a fluctuating number of users. However, the team system deserves some rethinking so that people can be in multiple teams and share different things with different coworkers.

I've only used it for two weeks, so I would be happy to hear about your use cases and how well Postman Cloud fits them. Please feel free to comment here or chat with me on Twitter!

Foucauld Degeorges

Xdebug With Postman Download

Web Developer at Theodo

Before you start debugging, make sure that you have a debugging engine installed and configured properly. PhpStorm supports debugging with two most popular tools: Xdebug and Zend Debugger. These tools cannot be used simultaneously because they block each other. To avoid this problem, you need to update the corresponding sections in the php.ini file as described in Configure Xdebug and Configure Zend Debugger.

With PhpStorm, a PHP debugging session can be initiated either through a run/debug configuration or without it. The latter approach is also called Zero-configuration debugging. PhpStorm supports three main ways to initiate a PHP debugging session:

  • You create a PHP Web Page debug configuration, and then PhpStorm uses its settings to launch the application, open the browser, and activate the debugging engine.

  • You create a PHP HTTP Request debug configuration or an HTTP request in the code editor, PhpStorm generates a request on its base, and then accesses a specific page through this request.

  • Zero-configuration debugging, when no debug configuration is created at all. Instead, you open the starting page of your PHP application in the browser manually and then activate the debugging engine from the browser, while PhpStorm listens to incoming debugger connections.

No matter which method you choose, you can specify the scripts requests to which you want PhpStorm to ignore during debugging. This approach can be useful, when your application contains scripts that use AJAX. Suppose you have a menu-ajax-script.php that 'reloads' a part of your web page. This script works properly so you do not need to debug it. However, this script is still requested during the debugging session. To have incoming connections to this script ignored, add the menu-ajax-script.php script to the skipped paths list.

If a script is added to Skipped paths, it is only skipped when starting a debugging session for it. To ignore a script when stepping through the program during a debugging session, configure a stepping filter.

When using Xdebug, you can also debug PHP applications in the multiuser mode via Xdebug proxy servers.

Pause a debugging session

Xdebug With Postman App

  • From the main menu, choose Run | Debugging Actions | Pause Program.

  • Click on the Debug toolbar.

    This action is not available for Run/Debug Configuration: Attach to Node.js/Chrome.

Resume a debugging session

  • From the main menu, select Run | Debugging Actions | Resume Program.

  • Click in the Debug tool window or press F9.

Restart a debugger session

  • Click in the Debug tool window or press Ctrl+F5.

Terminate a debugger session

Xdebug With Postman Free

  • Click the in the Debug tool window. Alternatively, press Ctrl+F2 and select the process to terminate (if there are two or more of them).