> > How would you go about ensuring the memory is not exhausted when running a > script ? > > I have a script, which to make it basic ... reads values from files, I > create an array of values per file then with a foreach insert values into a > table, I have added a line to echo the memory use after each array is done > (after insert is done and the foreach is complete for the file) with: -> > echo "Mem SQL: ".memory_get_usage() . "\n"; > > It gave me this result below: > > Mem SQL: 8341312 > Mem SQL: 8461856 > Mem SQL: 8693440 > Mem SQL: 9327008 > Mem SQL: 9798952 > Mem SQL: 10238392 > Mem SQL: 10604776 > > As can be seen the mem usage simply grows, > > I have added a line after each iteration of the foreach is complete to > unset > the vars and array ... thinking this would basically clear up the allocated > memmory used by the array ... and it would start at 0 again for the next > array looped, but obviously this is not quite the answer. > > The question is then how do you "clear" memmory then ? > I don't know what version of SQL you are using, but I have found that using: mysql_free_result($result); mssql_free_result($result); ifx_free_result($result); Helped my queries run much faster and use less resources. I had something similar to your script where I would read lines from a huge file and then insert the contents into my database. Before adding the above the process would take 20-30 minutes. After freeing the results after each insert my script completed in about 5-8 minutes. Just add that within your foreach loop after you execute your query that inserts the info. Hope that helps. Dan