memory_limit和memory_get_usage的關係

來源:互聯網
上載者:User
我先在伺服器上測試了下,當/etc/php.ini中memory_limit設定成16M時,memory_get_usage在頁面上輸出30135641,這時我就納悶了,那個數字不就是30M麼,比php.ini要大啊,怎麼沒警示。這兩者有什麼關係?望朋友們解惑!!!


回複討論(解決方案)

修改 php.ini 需要重啟web服務,你也可能改錯了位置

memory_limit 是可以在程式裡動態修改的

echo ini_get('memory_limit');//256Mini_set('memory_limit', '5M');echo ini_get('memory_limit');//5M

ini_set('memory_limit', '5M');$a = range(1, 60000);
Fatal error: Allowed memory size of 5242880 bytes exhausted (tried to allocate 36 bytes) in ...
$a = range(1, 58995);echo memory_get_usage() * Mb;
4.9964294433594
再加一就報錯

版主講得很詳細,受教了。

哦,明白了,樓上的方法很好,謝謝咯,原來上面的那個數字我看錯了,本來應該是3M的,我看錯30M了

我去,2樓啥時插進來的,把分都給你了,本來是給1樓的

哈哈,撿了個便宜,謝謝啦

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.