PHP debug practices

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

The old bird has a PHP debugging Manual that is popular on the Internet. No matter the old bird or the young bird, the purpose of this article is to introduce some simple and practical PHP debugging technologies. I hope you can provide valuable comments, make progress together.

(1) print the output

Use echo/print/print_r/var_dump + exit/die to output debugging results at the specified position and terminate program execution.

This method is not very good in PHP Ajax requests. If Ajax is a GET request, we can enter the Ajax URL in the browser to output our debugging information, however, if the POST method is used, the method cannot be changed.

(2) Enable the PHP error prompt Function

1. Set display_errors in the PHP. ini file to 1 or on, and restart Apache to make it take effect.

2. In the PHP program, use the set_ini ('display _ errors ', 'on') function to dynamically display program error information.

The setting for dynamically displaying errors in the program must be executed before the error occurs, so it is best to place it at the program entry point.

(3) view Apache error logs

1. in Linux, you can use

Tail/Your/path/to/error_file

To view the latest error logs in Apache.

2. In Windows, use NotePad to open the Apache error log file.

(4) xdebug/zenddebug

Xdebug supports remote debugging. It has two main features:

1. format the output information.

It overwrites the var_dump function of the system to make the output data more neat, beautiful, and easy to view. The only drawback is that when the displayed data volume is large, it hides the unrealistic part.

2. Remote debugging.

Xdebug consists of the xdebug server and 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 (the host and port for responding to the request can be configured)

Xdebug client <--------- (confirm connection information and return request page data) ---------------- xdebug Server

Xdebug client ----------- (send Debugging commands such as breakpoint and addwatch) ----------> xdebug Server

Xdebug client <--------- (receiving PHP Execution status information returned by the server) ---------------- xdebug Server

......

Xdebug client ----------- (Remote page request with xdebug session information is terminated) --------> xdebug server (disconnect)

Use xdebug in phpeclipse:

1. Install the xdebug extension. For detailed steps, see other network resources.

2. Set xdebug in phpeclipse

(1) specify to use the xdebug Debugger

(2) Specify the executable file path of PHP

(3) set remote host and Port

(4) set the request site and browser for debugging

(5) Press F11 to start debugging.

This article is not complete yet. I will try again later.

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/wirror800/archive/2010/10/30/5975653.aspx

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.