1

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. :)

Arash
  • 1,014
  • 1
  • 9
  • 17
  • 1
    Did you restart apache after changing the limit in php.ini? – robjingram Apr 14 '14 at 01:03
  • Assuming you changed the `memory_limit` setting in php.ini and restarted the apache service, did you make sure to update the correct php.ini file? (There are two, one for HTTP service and one for the command-line interface.) – faintsignal Apr 14 '14 at 01:26
  • I checked phpinfo() and it shows that memory_limit is set to -1, so it seems I have updated the correct one. I restarted apache, still no change :( – Arash Apr 14 '14 at 02:45
  • See if anything in this thread helps: http://stackoverflow.com/questions/4399138/upper-memory-limit-for-php-apache – faintsignal Apr 14 '14 at 03:36
  • but I'm also getting the same error we hosted in Hostgator shared server how can I access those files – Kishore Jan 30 '19 at 05:03

3 Answers3

4

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 and gc_collect_cycles() also are not effective. The only way is to use Function 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 adding memory_get_usage() once in your function and once out of the function to see the difference.

Arash
  • 1,014
  • 1
  • 9
  • 17
  • could you please help me in my issue?? http://stackoverflow.com/questions/34560732/phpmyadmin-import-error-of-memory?noredirect=1#comment56865264_34560732 – abu abu Jan 02 '16 at 05:08
2

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.

robjingram
  • 306
  • 1
  • 7
  • Thanks. Increasing memory_limit or set it to -1 did not help to solve the problem, – Arash Apr 14 '14 at 01:08
  • Are you seeing _exactly_ the same error with the same numbers? If so then there is something wrong with your change. Create a script containing `phpinfo();` and see what it says for the `memory_limit` and location of your php.ini file. Also restart apache to pick up the change – robjingram Apr 14 '14 at 01:19
  • I checked `phpinfo()` and it shows that `memory_limit` is set to -1 . And Im not seeing exactly the same numbers in errors. I restarted apache, still no change :( – Arash Apr 14 '14 at 02:43
  • What's your PHP version? See the note in the answer from @Sharanya-Dutta about needing this to be compiled in to PHP pre 5.2.1 – robjingram Apr 14 '14 at 02:47
  • Yes I saw that, my PHP version is 5.4.16 – Arash Apr 14 '14 at 03:27
  • See the article @faintsignal refers to above. You may be hitting 32 bit memory limits, which is going to be hard to fix if you can't change the code or the server – robjingram Apr 14 '14 at 03:39
  • Thanks robjingram , my system is 64-bits, but I have to use the 32-bit version because the function for stemming can be installed as extension only on 32-bits one. – Arash Apr 14 '14 at 04:03
1

Put this line at the beginning of your code:

ini_set("memory_limit", -1);

The PHP manual gives the following description of memory_limit:

This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts for eating up all available memory on a server. Note that to have no memory limit, set this directive to -1.

Prior to PHP 5.2.1, in order to use this directive it had to be enabled at compile time by using --enable-memory-limit in the configure line. This compile-time flag was also required to define the functions memory_get_usage() and memory_get_peak_usage() prior to 5.2.1.

When an integer is used, the value is measured in bytes. Shorthand notation, as described in this FAQ, may also be used.

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.

Community
  • 1
  • 1
Sharanya Dutta
  • 3,981
  • 2
  • 17
  • 27