NetBeans Tool uses xdebug breakpoints to debug PHP source code

Source: Internet
Author: User
Tags session id php source code zend netbeans

For experienced programmers, using functions such as Echo, Print_r (), Print_f (), Var_dump () is enough to debug PHP code, and if you need to use breakpoints debugging in IDE tools, Xdebug is a very good PHP debugging tool. For unfamiliar code, you can use Xdebug step-by-step view of the request process and the code execution process.

Preparatory work
Locally deployed server environment, it is recommended to use Phpstudy (built-in xdebug), open the PHP extension can be, do not download xdebug separately. (Download the xdebug:http://www.xdebug.org corresponding to the PHP version)


Configure the following three places
First, configure the php.ini, you should be aware of the use of integrated environment. Find the corresponding php.ini, for example, below is the php.ini of Phpstudy php5.3, where the black part is the system default, red is manually added.

[XDebug] xdebug.profiler_output_dir= "D:\phpStudy\tmp\xdebug"xdebug.trace_output_dir= "D:\phpStudy\tmp\ Xdebug "zend_extension=" D:\phpStudy\php\php-5.6.27-nts\ext\php_xdebug.dll "xdebug.remote_enable = 1xdebug.remote_mode=req; Note that the value of Remote_host is not available if you fill out localhost 127.0.0.1 xdebug.remote_host=127.0.0.1 ; Note that ports and Idekey are to be configured in NetBeans Xdebug.remote_port=9001xdebug.idekey=netbeans-xdebug

Second, restart the Apache server, check phpinfo () inside whether there is Xdebug, record Idekey (mine is Netbeans-xdebug).


This step is very important, because the pit is here ...
If you are always prompted to "Wait for NetBeans connection xdebug" when debugging PHP with NetBeans, use the command line to view the loaded modules and see if Xdebug is loading correctly.
At the command line, enter: php-m

When prompted: PHP Warning:xdebug must is loaded as a Zend extension in Unknown on line 0, meaning that Xdebug must be loaded into the Zend modules extension.
Extension is an extension based on the PHP engine, Zend_extension is an extension based on the Zend engine, so the correct way is to set the php.ini configuration file: Zend_extension=php_ Xdebug-2.4.1-7.0-vc14-nts.dll. If you use Phpstudy, the php.ini configuration file automatically increases this configuration when you enable the xdebug extension.
Also set in php.ini: Output_buffering = Off
  
Iii. Configuration of NetBeans
Configuration in NetBeans Tools-Options-php (NetBeans version 8.2)

    1. Tools-Options-php-General, PHP5 interpreter select Php.exe path (ex: D:\phpStudy\php\php-5.6.27-nts\php.exe)
    2. Tools-Options-php-Debugger port (9001, consistent with top php.ini), session id:netbeans-xdebug (consistent with Xdebug.idekey in top php.ini)

There is also a hole here, is the debugger port, the Internet is generally 9000, but there is no consideration of the use of Nginx, in the use of Nginx as a server Agent, Nginx is generally used is 9000 port! This is why we use port 9001 when we configure PHP for Xdebug.
The ports and Idekey in PHP.ini will be consistent with the debugger port and session ID in NetBeans, or the same hint: "Wait for NetBeans to connect Xdebug"!

After the configuration is ready, restart NetBeans and start debugging again.
After the configuration has been saved, or if the connection fails, restart NetBeans. many know that modifying the php.ini to restart the server. But I never thought that some of NetBeans's configuration would be restarted to take effect after it was changed .

Five, start debugging
Open a project (an existing project without creating a new project), and then choose Menu-Debug-debug project, which usually pops up http://localhost/index.php in the default browser? xdebug_session_start=netbeans-xdebug, the red parameter behind is the XDEBUG parameter, must have.
!!! Focus!!! If you want to debug a URL page Separately, add this parameter after the page? Xdebug_session_start=netbeans-xdebug or & Xdebug_session_start=netbeans-xdebug, and then open it to start debugging.

Reference article:
NetBeans Configuration xdebug Remote debugging PHP (http://blog.csdn.net/21aspnet/article/details/47756651)
Questions about NetBeans Breakpoint debugging PHP (https://www.oschina.net/question/232352_2209537)
Debugging PHP source code in the NetBeans IDE (https://netbeans.org/kb/docs/php/debugging_zh_CN.html)
Use NetBeans for PHP team development and multi-person remote debugging based on Xdebug (Http://starlight36.com/post/netbeans-use-for-php-team-with-xdebug)
PHP Breakpoint Debugging Tool--netbeans+xdebug Debugging PHP method (http://www.cnblogs.com/feichengwulai/articles/6252039.html)

Copyright NOTICE: This document is licensed under the attribution-Non-commercial use-sharing (CC BY-NC-SA 3.0 CN) International License Agreement, please specify the author and source.
Title: NetBeans Tool uses xdebug breakpoints to debug PHP source code
This article link: http://www.cnblogs.com/sochishun/p/7455032.html
This article Sochishun (e-mail: 14507247#qq.com | blog: http://www.cnblogs.com/sochishun/)
Published: August 30, 2017

NetBeans Tool uses xdebug breakpoints to debug PHP source code

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.