執行php程式的時候,報錯Allowed memory size of 134217728 bytes exhausted (tried to allocate 83 bytes)

來源:互聯網
上載者:User

標籤:執行php程式的時候   報錯allowed memory size of 134217728 bytes exhausted (tried to allocate 83 bytes)   

執行php程式時,會報下面的錯誤

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 83 bytes) in /mnt/Change/www/html/data/conn.php on line 18


 

第一種方法:不推薦

修改php設定檔php.ini,將memory_limit的值改大,但是不建議這麼做,因為無論修改的再大,有可能還是會報這個錯誤,因為不知道運行這個php代碼到底需要多少記憶體

 

第二種方法:推薦

一般都是一次賦值給變數的內容過多,比如把一張1GB的mysql表的內容一次性複製給一個變數,這樣肯定會導致運行記憶體超過了設定檔中限制的大小

 

解決方案

//第一步:先計算出這張表裡有多少記錄$sql=‘select count(*) as num  from table_name ‘;$Num_Res=Sql_Query($sql);//第二步:使用for迴圈和limit限制一次性取多少條內容,比如一次取100條記錄$Num=$Num_Res[0][‘num‘];for($i=0;$i<$Num;$i+=100){$a="select * from table_name limit $i,100";//具體的其他動作}

注意:Sql_Query()是我自定的方法,大家主要看的還是思路


本文出自 “技術” 部落格,請務必保留此出處http://hywds.blog.51cto.com/13158032/1958039

執行php程式的時候,報錯Allowed memory size of 134217728 bytes exhausted (tried to allocate 83 bytes)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.