I’ve tried to get over a millions of rows from a MySQL table to PHP my application.
Steps to get data are like bellow.
-
Send query to mySQL with mysql_query() or mysqli_query()..
-
Set result to array with looping each rows by using mysql_fetch_array().or add array by using mysqli_fetch_all().
I took messages ‘out of memory’ or ‘allowed memory size of * bytes exhausted’.
I might be able to solve them if I change ‘memory_limit’ .
But I want know why those message was shown.
I’ve changed ’memory_limit’ like 128M-> 512M ->1024M.
When I set 128M,sending query was failed with allowed memory size of *bytes exhausted and I can’t add result to array area.
Then setting 512M, query was finished successfully but I can’t add result to array with allowed memory size of * bytes exhausted.
Finally setting 1024M,both sending query and set result to add result to array was finished .but sometime mysqli_fetch_all() was field with Out of memory.
One thing I can’t understand is why Out of memory isn’t happen constantly?
One more thing I want know is How to get whole rows over a million from a table into PHP less memory turning. After getting whole rows I want let my user to access them by browser operation including download some types of file like csv.
You will get “allowed memory size of * bytes exhausted’” when the amount of memory needed exceeds the memory limit specified in php.ini file.
You will get “Out of memory” when the server itself (or Apache or MySQL) runs out of memory.