i’ve got seemingly simple php script running every night on one of my servers… on the same machine i started to experience nightly oom-killer.
i’ve found out that adodb’s Execute statement can do something completely else than you would expect from it – it loads whole result into memory rather than going row-by-row.
simplified code:
$r = $c->Execute('SELECT * FROM big_table'); while(($row=$r->FetchRow())!=false){ // process the data }
it was processing few gigabytes of results and recently – started to use more memory than was available on the server. problem was caused by this feature of adodb. apparently for mysqli driver it emulates row-counting by reading whole result to memory. magic fix – include this before heavy queries:
$ADODB_COUNTRECS=false;
and peak memory usage of my script dropped from 3GB dropped to 150MB.
edit: even with $ADODB_COUNTRECS=false; i’ve still experienced memory use problems with mysql driver, once i switched to mysqli all worked fine.