PHP Memory Analysis

Source: Internet
Author: User

1, generally speaking, PHP does not need to do memory analysis, but when encountering cycle memory is tight when you have to do memory analysis, see where to eat the memory.

$m 1 = memory_get_usage();

$m 2 = memory_get_usage();

.

.

.

$mn = memory_get_usage();

By subtracting up or down, you know the memory consumption situation.

Reference: http://www.laruence.com/2011/03/04/1894.html

Http://www.cnblogs.com/zcy_soft/archive/2011/04/12/2013223.html

2, when the method is called, it will allocate memory for its local variables, so to see if memory leaks, you should call the method before and after using memory_get_usage(), see the memory changes, if the method has a return value, Also consider the memory that the variable occupies;

When the memory is still large when the method is called, it depends on whether the memory is leaking or whether the data is cached

3, through the layer using memory_get_usage() analysis, find the memory consumption between the layers of similar places, and then quickly locate the memory leak method or function

2 and 3 points are experience

PHP Memory Analysis

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.