Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (CodeIgniter + XML-RPC)

前端 未结 29 2525
天涯浪人
天涯浪人 2020-11-21 22:57

I have a bunch of client point of sale (POS) systems that periodically send new sales data to one centralized database, which stores the data into one big database for repor

29条回答
  •  北荒
    北荒 (楼主)
    2020-11-21 23:22

    When adding 22.5 million records into an array with array_push I kept getting "memory exhausted" fatal errors at around 20M records using 4G as the memory limit in file php.ini. To fix this, I added the statement

    $old = ini_set('memory_limit', '8192M');
    

    at the top of the file. Now everything is working fine. I do not know if PHP has a memory leak. That is not my job, nor do I care. I just have to get my job done, and this worked.

    The program is very simple:

    $fh = fopen($myfile);
    while (!feof($fh)) {
        array_push($file, stripslashes(fgets($fh)));
    }
    fclose($fh);
    

    The fatal error points to line 3 until I boosted the memory limit, which eliminated the error.

提交回复
热议问题