ThinkPHP3.1 use of the new feature G Method

Source: Internet
Author: User

For a long time, ThinkPHP has to use the debug_start, debug_end methods, and even the Debug class to complete those debugging functions. In ThinkPHP3.1, these complex functions are replaced by a simple G method, this cannot be said to be a gorgeous upgrade.

The G method can be used to mark the location and interval statistics. The following describes the specific usage:

1. Mark the location

The first use of the G method is to mark the position, for example:

G('begin');

Mark the current location as the begin tag and record the execution time of the current location. If the environment supports this, it can also record memory usage. You can call the G method flag anywhere.

2. Running time statistics

After the position is marked, we can call the G method again for Interval statistics, for example:

G ('begin ');//... other code snippet G ('end ');//... maybe there are other codes // echo G ('begin', 'end') in the statistical interval '). 'S ';

G ('begin', 'end') indicates the execution time from the begin position to the end position (in seconds). begin must be a marked position, if the end position is not marked at this time, the current position is automatically marked as the end label. The output result is similar:

0.0056s

The default statistical accuracy is the fourth digit after the decimal point. If you think this statistical accuracy is not enough, you can set it as follows:

G('begin','end',6).'s';

The possible output will be:

0.005587s

3. memory overhead statistics

If your environment supports memory usage statistics, you can also use the G method for Interval memory overhead statistics (unit: kb), for example:

echo G('begin','end','m').'kb';

The third parameter uses m for memory overhead statistics. The output result may be:

625kb

Similarly,If the end label is not marked, the current position is automatically marked as the end label first..
If the environment does not support memory statistics, this parameter is invalid and the interval running time statistics are still performed.

Forget debug_start and debug_end. The greatest truths are simple, you know ~

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.