Error allowed memory size of 134217728 bytes exhausted (tried to allocate) when executing PHP program

Source: Internet
Author: User

The following error is reported when executing the PHP program

Fatal error:allowed memory size of 134217728 bytes exhausted (tried to allocate) bytes nn.php on line 18


The first method: not recommended

Modify php config file php.ini, Change the value of memory_limit, but do not recommend this, because no matter how big the changes, It is possible to report this error because you do not know How much memory is required to run this PHP code

The second method: recommended

It is generally a matter of assigning too much content to a variable at once, such as copying the contents of a 1GB mysql table to a variable at once, which will certainly result in running memory exceeding the size limit in the profile.

Workaround

First step: First calculate how many records in this table $sql= ' SELECT COUNT (*) as NUM from table_name '; $Num _res=sql_query ($sql);// Step two: Use the For loop and limit limits how many items to fetch at once, such as fetching 100 records at a time $num= $Num _res[0][' Num '];for ($i =0; $i < $Num; $i +=100) {$a = "select * FROM table_name limit $i, 100 ";//Specific other actions}

Note: Sql_query () is my self-determined method, we mainly look at the idea


This article is from the "Technology" blog, so be sure to keep this source http://hywds.blog.51cto.com/13158032/1958039

Error allowed memory size of 134217728 bytes exhausted (tried to allocate) when executing PHP program

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.