Remote multi-session debugging for PHP

Source: Internet
Author: User
Tags configuration php
This article mainly introduces to you about the PHP remote multi-session debugging related Materials, the text through the sample code and pictures introduced in very detailed, to everyone's study or work has a certain reference learning value, the need for friends below with small to learn together.

First, Background introduction

This article mainly introduce to you about the PHP remote multi-session debugging related content, share out for everyone to reference the study, the following words do not say more, come together to see the detailed introduction:

What to FIX: multiple project Breakpoint debugs, The Www.mysite.com project invokes the Api.mysite.com project rest interface, which makes it easier to directly debug the interfaces in the Api.mysite.com project when the action is triggered under the Www.mysite.com project.

What scenarios apply: cross-project debugging, remote debugging, and easier to use than simple var_dump.

Second, remote debugging configuration

NGINX+PHP-FPM environment, Configuration php.ini expansion


[xdebug]zend_extension =/usr/local/php56/lib/php/extensions/no-debug-non-zts-20131226/xdebug.soxdebug.remote_ Enable=1remote_handler=dbgpxdebug.remote_host=localhostxdebug.remote_port=9000xdebug.idekey=xdebug

Note: CLI environment PHP with FPM PHP whether to use different php.ini configuration files, need to configure FPM corresponding to the php.ini

Check that the configuration is correct

Map Remote (FPM host 10.99.1.185) port 9000 to local Port 9000:


Ssh-cng-r 9000:localhost:9000 root@10.99.1.185

You can use SSH commands directly after installing OpenSSH locally

The server can see that 9000 ports are occupied by SSH

Phpstorm also needs to configure Xdebug, which configures a debug session that is enabled for multiple, port 9000, to accept external requests.

Configuration item-related path mapping, domain name, port

Three, cross-session (project) Debug Configuration

The core of cross-project debugging is to send the conditions that trigger Xdebug debugging as parameters to the Api.mysite.com project or to other subsequent projects.

The WWW project code is as follows:

frontend.php


<?php$personjson = file_get_contents (' http://api.mysite.com/backend.php '); $person = Json_decode ($personJson); Var_dump ($person);

The API project code is as follows:

backend.php


<?phpclass person {public $Name;p ublic $Email;} $person = new Person (), $person->name = "Maarten"; $person->email = "maarten.balliauw@jetbrains.com"; Echo Json_ Encode ($person);

The WWW project needs to be modified to add the network request parameters that the XDEBUG needs to trigger remote debugging:


<?php$debuggingquerystring = '; if (isset ($_get[' Xdebug_session_start ')) {//xdebug$debuggingquerystring = ' Xdebug_session_start= '. $_get[' Xdebug_session_start ');} if (Isset ($_cookie[' xdebug_session ')) {//XDEBUG (COOKIE) $debuggingQuerystring = ' Xdebug_session_start=phpstorm ';} if (Isset ($_get[' Start_debug ')) {//Zend Debugger$debuggingquerystring = ' start_debug= '. $_get[' Start_debug '];} $personJson = file_get_contents (' http://api.mysite.com/backend.php '. $debuggingQuerystring); $person = Json_decode ( $personJson); Var_dump ($person);

Your own project can add cookie parameters to the generic network request encapsulation class:


curl_setopt ($this->ch, Curlopt_cookie, "Xdebug_session=xdebug");

Iv.. Commissioning Process

    • Ensure that the debug parameters have been forwarded to the API interface

    • Increase the number of sessions that can be debugged

    • Turn on debug snooping, Open the server xdebug

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.