Xdebug usage Daquan (i)

Source: Internet
Author: User

Xdebug is an open source PHP program debugger (a debug tool that can be used to track, debug, and analyze the health of PHP programs.

First, stacked error debugging

First of all, look at Xdebug's most basic function----------------------stack debug, code is simple, just have a function called T1, function require a nonexistent PHP file

function T1 () {require ' notexists.php ';} T1 ();

The execution results are as follows, and you can see very detailed error messages. The program executes the T1 function first, and then throws a fatal error in line 11 of the code.


Second, calculate the execution time of the script and the memory consumed

If you do not use Xdebug, the Microtime function is used to calculate the execution time, or the consumed memory is calculated through the Memory_get_usage/memory_get_peak_usage function. After installing Xdebug, you can use Xdebug_time_index and xdebug_memory_usage/xdebug_peak_memory_usage to implement. Note that the Xdebug_time_index () function returns the time that the script started executing from Mian to xdebug_time_index function execution.

The code is as follows:

echo "Xdebug_memory_usage:". Xdebug_memory_usage (); Echo ' Xdebug_time_index: '. Xdebug_time_index (); $arr =array (); for ($i =1; $i <=10000;++ $i) {Array_push ($arr, $i);} echo "Xdebug_memory_usage:". Xdebug_memory_usage (); Echo ' Xdebug_time_index: '. Xdebug_time_index (); while (!is_null ( Array_pop ($arr)) {}echo "xdebug_memory_usage:". Xdebug_memory_usage (); Echo ' Xdebug_time_index: '. Xdebug_time_index (); echo "Xdebug_peak_memory_usage:". Xdebug_peak_memory_usage ();//Display memory spikes








Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Xdebug usage Daquan (i)

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.