I am using WAMP server(32 bits) on local host on my personal PC. I have a big (very big) multidimensional array which gets its information by reading a CSV file which contains long sentences(the CSV file contains 20,000 row of information). The problem is that I get the following error when it goes through some calculations:
Fatal error: Out of memory (allocated 1134559232) (tried to allocate 32768 bytes) in x:\wamp\www\xxx
I tried different solutions like increasing upload_max_filesize
, post_max_size
, max_file_uploads
and memory_limit
or set it to -1 in php.ini or at the beginning of my scripts also, no one works. Please help me, and please do not ask me to re-architect my codes or change the version of WAMP, due to some reasons it is not possible. Thank you very much. :)
Put this line at the beginning of your code:
The PHP manual gives the following description of
memory_limit
:I don’t know what makes them so confident that only poorly written scripts need to adjust this setting but I hope this brief introduction fulfils your need anyway.
Finally I could find the solution. I found that when the PHP collection garbage is getting full, there is no way to free it.
Unset
andgc_collect_cycles()
also are not effective. The only way is to useFunction
over different section of codes. In my case, I had a big script in a for loop, so I copied all my codes in a function, and in my loop I call the function. Each time function quiets, memory gets free. You may test it by addingmemory_get_usage()
once in your function and once out of the function to see the difference.It's none of those settings, it is
memory_limit
, the max amount of memory that a PHP script can consume. However, be sure that your server has enough resources before arbitrarily increasing this setting.