PHP Debug Actual Combat technology ____php

Source: Internet
Author: User
Tags apache error log php debug

Veteran has a "PHP debugging Manual" in the network popular, regardless of the veteran or tender birds, the role of this article is to introduce some simple and easy to debug the actual combat technology, I hope we can put forward valuable advice and common progress.

(i) Print output

Use Echo/print/print_r/var_dump+exit/die to output debug results at the development location and terminate program execution.

This trick in the PHP Ajax request is not very good, if Ajax is a get-way request, we can enter the Ajax URL in the browser to output our debugging information, but if it is post, the way to change a bit powerless.

(ii) Turn on PHP's error tip feature

1. Set the display_errors in the php.ini file to 1 or on, and then restart Apache to take effect.

2. In the PHP program, use the Set_ini (' display_errors ', ' on ') function to dynamically display the program error message.

The setting of a dynamic display error in a program must be performed before the error occurs, so it is best to place it at the entry point of the program.

(iii) View the Apache error log

1. In a Linux environment, you can use

Tail/your/path/to/error_file

To view the most recent error log that occurred in Apache.

2.windows, open the Apache error log file directly with Notepad to view it.

Four Xdebug/zenddebug

Xdebug can realize the remote debugging function, it has two major features:

1. Format of output information.

It rewrites the system's Var_dump function, can make the output data more neat, beautiful, easy to view. The only drawback is that when the amount of data displayed is large, it hides the part that is not realistic.

2. Remote Debugging function.

Xdebug work process mainly consists of two parts: Xdebug Server, Xdebug Client. It looks a bit like a backdoor program that is parasitic in Apache. It works as follows,

XDebug Client-----------(Remote page request with XDebug session information)----------->xdebug Server (can configure host and port to respond to requests)

XDebug client<---------(Connection information Confirmation and return request page data)------------------XDebug Server

XDebug Client-----------(send debug commands such as breakpoint, Addwatch, etc.)---------->xdebug Server

XDebug client<---------(Receiving the PHP execution status information returned by Server)------------------XDebug Server

......

XDebug Client-----------(Termination of a remote page request with XDebug session information)-------->xdebug Server (disconnected)

Using Xdebug in PHPEclipse:

1. Install Xdebug extension, please refer to other network resources for detailed steps.

2. Set up Xdebug in PHPEclipse

(1) Specifying the use of the Xdebug debugger

(2) Specify the path of PHP executable file

(3) Set up remote host and port

(4) Set up the request site and the browser for debugging

(5) Press F11 to start debugging it.

This article is not complete, and so there is time for further finishing.

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.