This article mainly describes how to use Vim + xhttp://www.php.cn/code/8684.html "target=" _blank ">debug debug PHP program on the server, although there are many ways to introduce how to use Eclipse + Xdebug Debugging PHP articles on the developer's machine, but for how the system is configured VIM + xdebug is relatively small, and the current article on vim settings is used with an older plugin. Here is the main introduction of a new plugin Dbgpavim, it has many advantages over the old plug-ins. At the same time the plug-in can be perfect for the Python program debugging. In addition, VIM + Xdebug has many advantages over eclipse + Xdebug, which will be described in the article.
DBGP is a protocol for debugger background and debugger interface communication for debugging multiple scripting languages. Xdebug is the DBGP implementation for debugging PHP. Vim and xdebug interoperability, the implementation of PHP debugging, need to be able to understand the DBGP protocol, and can send DBGP instructions. Dbgpavim is a plugin that enables VIM to accept DBGP requests and send DBGP instructions for debugging purposes. Dbgpavim's name originates from Dbgp@vim.
ActiveState provides a DBGP implementation Komodo Remote debugging package for debugging Python/ruby, followed by a section on how to make it interoperable with vim to debug python. Users will be able to roll out how to debug scripting languages such as Ruby/nodejs in this class.
Installation Xdebug can refer to Http://xdebug.org/docs/install.
To edit php.ini, add the following two lines:
Edit your httpd.conf and add the following lines:
Php_value Xdebug.remote_autostart 1
Note: This line is not necessary, if you do not add this line, you need to access the HTTP server URL to add xdebug_session_start=1 parameters, such as: Http://localhost/index.php?XDEBUG_SESSION_START=1.
If you have multiple developers who need to debug different virtualhost at the same time, you can add the following line to your VirtualHost segment:
Php_value Xdebug.remote_port 9009
Note: The 9009 here is vim as the DBGP server should listen to the port, different developers in different virtualhost with their different port numbers. This port number is consistent with the dbgpavimport mentioned in the next section. Without this line, the default port number is 9000.
Finally, you can check that your xdebug configuration is correct by phpinfo.php, and you must be able to see the following values for these rows (mainly the first two columns):
Xdebug.remote_autostartonoff Xdebug.remote_enableonon XDEBUG.REMOTE_HANDLERDBGPDBGP Xdebug.remote_ host127.0.0.11222.214.171.124 xdebug.remote_port90099000
The contents of the phpinfo.php file are as follows:
<?php phpinfo ();?>
Configure Vim + Dbgpavim
The Dbgpavim plugin itself is implemented in Python, so you need vim support for Python 2.7. Open your vim and enter the command
If you can see "+python", it means that your vim is supported by Python. If you see "-python", it means that your vim does not support Python, you can compile your vim as follows:
Installing Python 2.7
Export Path=/path/to/python2.7/bin: $PATH
Compile vim with the following command:
./configure--prefix=/opt/vim--enable-pythoninterp--with-python-config-dir=/usr/lib/python2.7/config make make Install
Note: The/usr/lib/python2.7/config here depends on where you install the Python2.7.
Download Dbgpavim from here or here, put it in your ~/.vim directory, and edit your ~/.VIMRC, adding the following two lines:
Let G:dbgpavimport = 9009let g:dbgpavimbreakatentry = 0
Note: Here the 9009 and the previous section of 9009 to be consistent, if the previous section is not configured Xdebug.remote_port, there is no need to configure, because they will use the default of 9000. Dbgpavimbreakatentry=0 tells Vim not to stop at the entrance, so it will only stop at the breakpoint.
You can restart Vim and press F5 to check if your dbgpavim configuration is correct. If you configure success, you will do the following in the lower right corner of the Vim window to see the following message:
It indicates that VIM is currently listening on port 9009, BAP indicates that it will only stop at the breakpoint, and the other message formats are as follows:
<bae|bap>-<lisn| pendn| conn| Clsd>
Bae breaks at Entry, stops at the entrance of BAP break only at breakpoints, stops at the breakpoint only
The LISN debugger is started and is in the listening state. The Pend-n debugger has captured the connection request and can press F5 to enter debug mode. The Connvim is in debug mode. The CLSD debugger has stopped.
Debug PHP in Apache environment
Now that the configuration is correct, you can use VIM to open the file you need to debug, jump to the line you need to debug, press F10 to set the current behavior breakpoint, and press F5 to start the debugger.
Using a browser to access the URL that invokes the appropriate PHP file, you will see a hint in the VIM status bar that changes to:
It tells you that there is already a connection being intercepted and can press F5 to start debugging.
Press F5 to enter debug mode and you will see that the Vim window is divided into three parts: the source window on the left, the variable viewing window on the right, and the call Stack window below. In the source window, position the cursor over a variable by pressing F12, and you can see the value of the variable in the Variable view window, and if the variable is not a simple variable, its members are displayed. If a member of the variable is still not a simple variable, a plus sign will appear after the line, and the value of the member will continue to expand when the row presses the ENTER key. If you want to view the member variables of a variable directly, you can switch to visual mode by pressing V, select the member and press F12, such as $this->login. In the Stack window, when you press ENTER on a row, you will jump to that layer. The top row is the lowest, and the bottom row is the topmost. Switching the hierarchy of call stacks can help you see variables at various levels, such as some global variables that can only be seen at the top level. For variables that do not appear in the source code, you can view them by command: PG, for example:
You can start your debugging, press F1 at any time to bring up the Help window, again F1 close the Help window.
Debugging a command-line-initiated PHP program
If you need to debug the command line to start the PHP program, you also need to ensure that the PHP terminal settings are correct. These settings can be set in php.ini as before, or by command line parameters. Like what:
If your command line uses the same INI as the php5_module used in Apache (which is usually the case), you do not need to make these settings in the parameters. But if your settings in the INI are placed in a virtualhost segment, you still need to add these settings. You can use the command line:
To see which ini your command line is using.
Then you can use the command:
Php-r "Phpinfo ();" | grep Xdebug.remote_
To check your xdebug settings.
The basic steps are as follows:
Use VIM to open the PHP file you need to debug, F10 set breakpoints, F5 start debugging monitoring.
Run the PHP program from the command line as above.
Back to your Vim window, you will see a hint message for PEND-1.
Press F5 to enter debug mode.
Dbgpavim provides a: DP command simplifies debugging of the command-line program. Just open your php file and enter the command: DP.
Debugging Python Programs
As previously mentioned, Vim + Dbgpavim as a server for the DBGP protocol, can work with Xdebug, and can work in conjunction with Komodo Python Remote debugging client provided by ActiveState. To implement the Python program debugging, the following steps:
Download the install Komodo Python Remote debugging Client From here, add the extracted bin directory to your path path, and note the PYDBGP file under the bin directory.
Use Vim to open the Python file you need to debug, F10 set breakpoints, F5 start debugging monitoring.
Run your Python program through PYDBGP, such as
pydbgp-d 127.0.0.1:9009 test.py
The above: DP command also applies to Python debugging, debugging Python with Gvim + PYDBGP for Windows 7.
The advantages of VIM + Dbgpavim vs. eclipse + Xdebug
Most servers do not start Xserver and cannot start eclipse on the server. If you start Eclipse + XDebug on a developer's machine, it's equivalent to running the DBGP server on a working machine, you need to set the path map, which is the code that HTTP server executes on the server, and the Eclipse debugging is a code that opens on the work machine, To ensure that the two code can correspond to the need to map the path. When the program size is small, the problem is not big, when the program is large, will be more troublesome, and to ensure that the code synchronization, otherwise it will be serial.
You can also encounter problems such as network firewalls.
VIM + Dbgpavim is also supported for remote debugging, but also avoids the path mapping settings, as follows:
Let G:dbgpavimpathmap = [[' d:/works/php ', '/var/www '],
Note: The 9009 port here is equivalent to the Xdebug.remote_port set up for PHP debugging, which needs to be consistent with Dbgpavimport.
Back to your Vim window, you will see a hint message for PEND-1.
Press F5 to enter debug mode.
Dbgpavim Benefits relative to other plugins
Dbgpavim originates from a DBGP plug-in http://www.vim.org/scripts/script.php?script_id=1152 in early vim, which also derives some other DBGP plugins from this plugin. But Dbgpavim rewrite the DBGP server as the debugger background, asynchronous listener, so that vim listens to the DBGP without interfering with the interaction between the user and Vim. Users press F5 to start debugging monitoring, you can continue to use VIM, at any time can press F6 stop monitoring.
Dbgpavim listens to all DBGP connections from DBGP clients such as Xdebug and PYDBGP, unlike other plug-ins that capture only the first connection. This is necessary for large-scale Web applications, because a page load now typically triggers multiple HTTP requests, and we need to debug any one of them. At the same time Dbgpavim support only stop at the breakpoint, the other plug-ins are stopped at the entrance, requiring the programmer to follow the step-by-step. This saves developers a lot of trouble and avoids restarting debugging again and again after a mistake.
I believe you have also found that Dbgpavim can work with Gvim under Windows and work very well.
Dbgpavim reference for detailed use
VIM Normal Mode
F5 start Debug Monitoring, or you can enter debug mode when a debug connection is available. F6 Stop Debugging monitoring. F8 switch the value of dbgpavimbreakatentry, press this button you can see the status bar prompt information between Bae and BAP switch, that is, whether to stop at the entrance of PHP program. F10 Sets or removes breakpoints on the current line, which is also true in debug mode.
F1 Open or close the Help window F2 step into F3 step over F4 Single step exit F5 continue execution until the next breakpoint, and exit debug mode if no breakpoints follow. F6 Stop Debugging, this button will cause Vim to exit the debug mode, and stop debugging monitoring. F7 debugging when the execution of the PHP statement, after F7, the user can enter the variable viewing window PHP statement, enter after the execution. F9 maximizes a child window, or resets the window layout. F11 view the values of all variables under the current execution environment, with different results at different stack levels. F12 View the value of the variable under the cursor.
The above function keys are the default configuration, if you are accustomed to the key settings of most browsers, you can add the following code to your. VIMRC:
Let G:dbgpavimkeyrun = ' <F8> ' let g:dbgpavimkeystepover = ' <F10> ' let G:dbgpavimkeystepinto = ' <F11> ' Let g:dbgpavimkeystepout = ' <F12> ' let g:dbgpavimkeypropertyget = ' <F3> ' let G:dbgpavimkeycontextget = ' < F4> ' Let g:dbgpavimkeytogglebp = ' <F9> ' let g:dbgpavimkeytogglebae = ' <F5> ' let g:dbgpavimkeyrelayout = ' <F2> '
Vim command, all commands have only the first letter in uppercase.
:BL lists all breakpoints: BP and F10 function the same p This command can be used to quickly debug the current file, which implements the following functions: 1. Check that the XDEBUG/PYDBGP settings on the command line are correct 2. Start the debugger Listener 3. Use PHP/PYDBGP to execute the current file G <longfoo> View the values of the longer variables, such as: Pg $this->savings:up Call stack up to level n call stack down one level: Wc [$foo] Open/close to variable $ Foo's surveillance. If there are no parameters, all variables under the current execution environment are monitored. : We <foo> turn on/off monitoring of statement Foo, which automatically executes the Foo statement after each step. : WL lists all the variables or statements that are being monitored. : Children <n> The first 1024 elements are displayed for the array by default, this command can be modified. Epth <n> for complex variables, the default is to show only the next layer of members, which can be set to limit multiple layers. : Length <n> for string variables, the default execution displays the first 1024 characters, which can set the display length.