For PHP memory release related issues

Source: Internet
Author: User
For PHP Memory release issues

When you use the Phpexcel class, when you open a larger Excel data document, the fatalerror:allowed memorysize of 67108864 bytes exhausted (tried to allocate bytes) in example/admin/add_mysql.php on the line, the error is that the page memory is exhausted. Now let me take a look at the solution:

I think of two kinds, the first is to expand the memory that PHP can use:

1, in the php.ini file, modify the memory_limit:80m, the value of the actual situation of their respective decisions.

2, in PHP file, directly use In_set ("Memory_limit", "80M") to modify the memory limit.

The above situation only applies to local and virtual host, on the general space server or development platform is basically not allowed, let me say the second, as far as possible to reduce the page PHP execution memory consumption:

Use the unset () statement.

1, release variables: Online There are many use cases are used for variables, in fact, but in this case, when you unset a variable, it takes up the memory does not return to the system, but is occupied by the symbolic variable, (detailed can Baidu, there are many explanations).

2, release the object: especially when using the Phpexcel class, read a relatively large file, its objects will occupy a large amount of memory, for example:


Operation Result:


When we use unset:


Operation Result:


wow! , it is surprising that the release of variables will not reduce space, but the release of the object is very obvious, compared to a total of less than 33 million bytes, hoping to help people solve the problem, for the reasons I am not very clear, I hope the master can explain.

  • 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.