Uniform Server PHP IDE: XDebug Overview

From The Uniform Server Wiki
Jump to navigation Jump to search

 

MPG UniCenter

Uniform Server PHP IDE.

XDebug Overview

XDebug is a main building block of the Uniform Server PHP IDE. XDebug along with Notepad++’s debugging client provides debugging capabilities for both CLI scripts and Web Page scripts.

XDebug’s versatility allows it to run on a server or from a command line. The debugging architecture differs slightly and this page provides an overview of these different architectures.

PHP CLI Debugging

Debugging a PHP CLI script requires control of the PHP interpreter and a mechanism to separate script flow and error messages generated. A debugging client must provide unobtrusive communication with the interpreter while allowing a script to run.

The PHP extension php_xdebug.dll seamlessly installs code to provide interpreter control and communication between a client (Notepad++ with DBGp plugin installed in the IDE) and the PHP interpreter over port 9000. Effectively php_xdebug.dll includes a mini server to provide communication with a client.

Sequence of events

  • Step A) Run Notepad++.
  • Step B) Start Notepad++'s client (DBGp plugin) which opens socket 9000
    (listens on port 9000)
  • Step C) Run script from Notepad++ (Executes PHP interpreter).
  • Step D) Interpreter loads configuration file and loads extensions (php_xdebug.dll)


  • Step E) XDebug establishes contact with client.
  • Step F) Script is loaded and run.
  • Step G) Script execution (debugging) is controlled by client.


Note 1: Debugging is initiated as soon as the interpreter loads XDebug.

Note 2: If the script is initiated from an external source (for example, a batch file), XDebug determines if the script (F) is displayed in Notepad++. If not, it is downloaded.


Note 3: If XDebug starts debugging a new page, that page is downloaded if not already displayed in Notepad++.

Ide xdebug 1.gif

Web Page Debugging

Debugging a website running on a local server effectively requires a second server and client. This second server and client taps into the primary server and web site to provide debugging and control of that site and server.

The second server is created using a PHP extension (php_xdebug.dll). It seamlessly installs code to provide communication between Apache and a client (Notepad++ with DBGpplugin installed) over port 9000. In addition, code is installed to monitor browser requests arriving on the standard Apache port 80.

Sequence of events

Assumes Uniform Server running (Apache server running).

  • Step A) Start Notepad++.
  • Step B) Notepad++'s client DBGp plugin opens socket 9000 (listens on port 9000)
  • Step C) In a browser, enter address of PHP page to be debugged.
  • Step D) Browser requests this page from Apache server over port 80
  • Step E) Apache runs the PHP interpreter
  • Step F) PHP interpreter runs its extensions including the XDebug module.


  • Step G) XDebug module starts remote debugging.
  • Step H) XDebug connects to debugging client over port 9000


  • Step I) User uses client for debugging. Commands and data are sent over port 9000
  • Step J) Client can instruct XDebug to execute one or more php statements. Your PHP code is executed; this may output data over http Port (80) to web browser.


  • Step K) When all your PHP code has been executed, XDdebug disconnects from client.
  • Step L) Followed by Apache closing connection to browser.

Ide xdebug 2.gif

Note 1: Debugging is initiated from a browser. XDebug determines if the page is displayed in Notepad++ and if not, it is downloaded.

Note 2: If XDebug starts debugging a new page, that page is downloaded if not already displayed in Notepad++.

Note 3: During debugging, the browser shows page loading

Note 4: After step A) you can directly load, edit and save the page to be debugged. After enabling the debug client at step B) you can set break points and then imitate a debug session via the browser, Step C. The next page covers this in more detail.


Summary

The above block diagrams show the commonality between the two architectures, which are essentially the same. Each uses Notepadd++’s client plugin for debugging. This is covered in detail on the next page.