Tp3 circulates using the array add operation add method, which results in an increasing amount of memory.

    G("begin");
    $model = M("test_data");
    $list = M("test_ids")->getField("id",true);
    foreach ($list as $k => $v) {
        $data = [];
        $data["params"] = $this->params;
        $temp_arr = $this->post($this->url,$data);

        $json_data = json_encode($temp_arr);
        $a_data = [];
        $a_data["json_data"] = $json_data;
        $model->add($a_data);
        unset($a_data);
        G("end");
        echo G("begin","end","m")."kb"."<br>";

    }
    
    
    :
 
    

$model->add()

Why does the add method of tp3 cause memory to increase continuously?

Mar.13,2021
For the consumption of more than a dozen database inserts in the

cycle, let's use bulk inserts


put model into the traversal of foreach, and then model instantiated by unset

G('begin');
    
    $list = M('test_ids')->getField('id',true);
    foreach ($list as $k => $v) {
        $model = M('test_data');
        $data = [];
        $data['params'] = $this->params;
        $temp_arr = $this->post($this->url,$data);

        $json_data = json_encode($temp_arr);
        $a_data = [];
        $a_data['json_data'] = $json_data;
        $model->add($a_data);
        unset($a_data);
        G('end');
        echo G('begin','end','m').'kb'.'<br>';
        unset($model);
    }

in this case, replace it with a SQL statement and insert it directly. SQL operations should be avoided as much as possible in the loop.


caused by the underlying trace and logs, close debug, and modify the trace configuration.
add entry file

define('APP_DEBUG', false);

there are three cases in which the trace method logs:

  1. AJAX request
  2. SHOW_PAGE_TRACE is false, that is, when the page Trace is closed
  3. The fourth parameter of the
  4. trace method is true

therefore, trace logging can be avoided with the following configuration:

C('DB_DEBUG', false); // SQL  
C('TRACE_MAX_RECORD', 0);  
C('SHOW_PAGE_TRACE', true); // TRACE_MAX_RECORD
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf598f-312ea.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf598f-312ea.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?