catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.83k stars 1.15k forks source link

Memory usage #237

Closed netxdesign closed 7 years ago

netxdesign commented 9 years ago

I'm generating a number of inserts in a object loop and eventually I run into memory usage problems. By checking the memory usage after each loop cycle the memory requirements have increased.

Connection: $db = new medoo( array( 'database_type' => 'mysql', 'database_name' => DBASE_NAME, 'server' => MYSQL_HOST, 'username' => MYSQL_USER, 'password' => MYSQL_PW, 'port' => 3306, 'option' => [ PDO::ATTR_CASE => PDO::CASE_NATURAL, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false, PDO::ATTR_PERSISTENT => true ], 'charset' => 'utf8', ) );

Typical inserts in each loop:

if ((int)$tag >= 000 && (int)$tag < 100) $db->insert( 'T0xx', $cdata ); elseif ((int)$tag >= 100 && (int)$tag < 200) $db->insert( 'T1xx', $cdata ); elseif ((int)$tag >= 200 && (int)$tag < 300) $db->insert( 'T2xx', $cdata ); elseif ((int)$tag >= 300 && (int)$tag < 400) $db->insert( 'T3xx', $cdata ); elseif ((int)$tag >= 400 && (int)$tag < 500) $db->insert( 'T4xx', $cdata ); elseif ((int)$tag >= 500 && (int)$tag < 600) $db->insert( 'T5xx', $cdata ); elseif ((int)$tag >= 600 && (int)$tag < 700) $db->insert( 'T6xx', $cdata ); elseif ((int)$tag >= 700 && (int)$tag < 800) $db->insert( 'T7xx', $cdata ); elseif ((int)$tag >= 800 && (int)$tag < 900) $db->insert( 'T8xx', $cdata ); elseif ((int)$tag >= 900 && (int)$tag < 1000) $db->insert( 'T9xx', $cdata ); ... ... ... $db->insert( 'nc_main_catalogue', $cat_recs );

There is up to 3 SELECTS per loop on a very simple table:

$r = $db->get( 'nc_marcto_nc', [ 'ind1', 'ind2' ], [ "tag" => $tag ] );

I'm pretty sure that the memory requirement is not down to the object loop as I have run this without DB access and the memory usage does not increase.

Any ideas?

quantuumsnot commented 9 years ago

Where's the problem to use this: $tagString = substr($tag, 0, 1) . "xx"; $db->insert($tagString, $cdata);

playgamelxh commented 9 years ago

you should add a function. Such as public function clear() { $this->logs = array(); }