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

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.

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

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀