dongxu1029 2014-04-18 17:50
浏览 60
已采纳

致命错误:Magento允许的内存大小为134217728字节

In Magento I got this error. I know this is a memory issue, but I know my code causing this. How can I solve such issue? The same code works for long time and suddenly it generates issue.

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 94115841 bytes) in /home/wwwcruk/public_html/cas/app/design/frontend/default/cas/template/brandproduct/brand-listcar.phtml on line 60

I allocated 256M from htaccess. When I remove code from above file it works.This is the part of code. These are the two lines ($manufacturer['label'][0] == $char) that are causing the issue:

 <?php $i=0;$j=0;foreach ($manufacturers as $manufacturer): ?>

<?php if($i == 0 && $manufacturer['label'][0] == $char): $j++;?>

    <li><span class="levelchar"><?php echo $char; ?></span></li>

<?php endif; ?>

<?php if($j>=$heightColumn):?>

    </ul>

    <ul class="level-brandul">

<?php $j=0; endif;?>

<?php while( $manufacturer['label'][0] != $char){ $char++;?>

    <?php if( $manufacturer['label'][0] == $char): $j++; ?>

    <li><span class="levelchar"><?php echo $char; ?></span></li>

    <?php if($j>=$heightColumn):?>

    </ul>

    <ul class="level-brandul">

<?php $j=0; endif;?>

<?php endif; ?>

<?php }?>

I still got the error after increasing memory limit.

[Mon Apr 21 10:52:52 2014] [error] [client 82.94.176.140]  in /home/wwwcruk/public_html/cas/app/design/frontend/default/cas/template/brandproduct/brand-listcar.phtml on line 47, referer: http://creationsautosport.co.uk/cas/index.php/catalog/product/view/id/58/s/bmw-m-power-silver-number-plate-surrounds/category/4/
[Mon Apr 21 10:49:50 2014] [error] [client 82.94.176.140] Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 504104961 bytes) in /home/wwwcruk/public_html/cas/app/design/frontend/default/cas/template/brandproduct/brand-listcar.phtml on line 47, referer: http://creationsautosport.co.uk/cas/index.php/catalog/product/view/id/58/s/bmw-m-power-silver-number-plate-surrounds/category/7/
[Mon Apr 21 10:47:08 2014] [error] [client 82.94.176.140] Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 504104961 bytes) in /home/wwwcruk/public_html/cas/app/design/frontend/default/cas/template/brandproduct/brand-listcar.phtml on line 47, referer: http://creationsautosport.co.uk/cas/index.php/catalog/product/view/id/58/s/bmw-m-power-silver-number-plate-surrounds/category/9/
[Mon Apr 21 10:46:56 2014] [error] [client 39.47.121.31] Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 496762881 bytes) in /home/wwwcruk/public_html/cas/app/design/frontend/default/cas/template/brandproduct/brand-listcar.phtml on line 47
  • 写回答

3条回答 默认 最新

  • dszsajhd237437 2014-04-18 20:32
    关注

    This seems irregular certainly. But can you put more code in your question? Is it just that your while loop doesn't have a break if $char or $J is greater than some large number. We can't see what your whole loop is trying to do.

    What is the code you are removing? It isn't just these two lines is it?

    I would also say that 256M maybe isn't a huge amount of memory. If you up it do you still hit the new limit?

    ***EDIT following comments below:

    Thank you for adding all the code. I'm sure you have analysed your code, but my only comment from here is about how the while loop functions. It seems $char is an integer number presumably counting up from 0 and you are matching that to a manufacturer label or level. Good, nothing wrong with that plan.

    But perhaps $char should be set back to zero at the very start of the foreach loop:

    <?php
        $i=0;
        $j=0;
        foreach ($manufacturers as $manufacturer):
          $char = 0;//or whatever its initial value should be
          //...
    ?>
    

    Because if the order of $manufacturer in $manufacturers is not ordered by increasing $manufacturer['label'][0] then the while loop will never stop because on eg the fifth iteration of the foreach loop $char might be 8 and $manufacturer['label'][0] might be 4.

    Does that make sense? I don't know your code, but the while loop has no alternative exit and I think even if it is impossible, adding a fail-safe to the while loop would be prudent. Such as:

    <?php
    
        $bailAt = PHP_INT_MAX - 1;//this is a very large number => wait a long time to bail
        $bailAt = 32000; //if you have over 32000 manufacturers in Magento you probably have other issues too
        while( ($manufacturer['label'][0] != $char) && ($char < $bailAt) ){
          $char++;
    
          //...
        }//end while
        if ($char==$bailAt){
           //recover gracefully
           echo("<!-- there was an error building the manufacturer levels (reached maximum levels) -->");
           echo("</ul>"); //you might not need that
        }//end if
    ?>
    

    But check the ordering of $manufacturers and reset $char to 0 at some point and see if it fixes things. If you do need to increase the memory and your system can't use ini_set() then you can edit php.ini file instead and set the memory limit there (and don't forget to restart your web server to apply the php.ini changes).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!