Home > Mobile >  Fatal Error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 262144 bytes) on li
Fatal Error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 262144 bytes) on li

Time:10-13

I am getting this error in codeigniter 3. I had tried most of the things but none of them worked.

    function money_format($num = 0, $pro = 2)
    {
        %number =round((float)$num, $pro);

         if($pro == 2)
            $num = money_format("%!^2n",(float)$num);
         else
            $num = money_format("%=*!^.".$pro."n",(float)$num);
         return $num;
     )}

CodePudding user response:

  1. Increase memory_limit in your php.ini file. If this is not resolving the issues:

2) Add this line ini_set('memory_limit', '-1'); before the line where you get the error

CodePudding user response:

You're getting an infinite loop because this function is recursive without a stop condition.

It'll always calls itself until there is no memory left.

If I could suggest an alternative, I would say to use the number_format function. Its a native php function, take a look at the documentation.

  • Related