doupingdiao3546 2017-06-05 18:41
浏览 639
已采纳

PHP致命错误:允许的内存大小为268435456字节

I am getting the following error when clicking on a category named Test

FastCGI sent in stderr:

PHP message: PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 32 bytes) in /home/mydomain/public_html/app/functions/fn.catalog.php on line 736" while reading response header from upstream, client: 24.xx.xx.xx, server: www.mydomain.com, request: "GET /test-page-313/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.mydomain.com", referrer: "http://www.mydomain....lesale-towels/"

My 736 Line is as follows

In my php.ini I've already increase the memory_limit to = 1G

for ($qty = $min_qty; $qty <= $max_qty; $qty += $product['qty_step']) {
    $qty_content[] = $qty;
}
  • 写回答

1条回答 默认 最新

  • dqy1265 2017-06-05 18:57
    关注

    Several possibilities :

    • $product['qty_step'] doesn't contain a number
    • There are two many steps in your loop that makes your program creating many entries in the $qty_content array.

    For example, if you have:

    $min_qty = 0;
    $max_qty = 400000;
    $product = array("qty_step" => 0.001);
    $qty_content = [];
    
    // The loop
    for ($qty = $min_qty; $qty <= $max_qty; $qty += $product['qty_step']) {
        $qty_content[] = $qty;
    }
    

    The program will try to make up to 400000000 entries in the array, which takes so much memory that PHP can't handle it. So it throws the error you've got. As someones said in your question's comments, try to debug the content of all variables, for example:

    var_dump(
      array('qty' => $qty,
        'min_qty' => $min_qty,
        'max_qty' => $max_qty,
        'product["qty_step"]' => $product['qty_step'])
    );
    

    And see what you get. In all cases, this error means you're taking too much memory, so you must reduce the loop's iterations by increasing $product['qty_step'] or reducing the difference between $min_qty and $max_qty.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效