1

one of my script required large memory. and probably because of this I am getting following error

Fatal error: Out of memory (allocated 42729472) (tried to allocate 32 bytes)

I tried to change memory_limit by using ini_set('memory_limit', '256M'); on the top of my page but still I am getting same issues. I also tried ini_set('memory_limit', '512M'); but no luck.

hakre
  • 193,403
  • 52
  • 435
  • 836
Prakash
  • 2,749
  • 4
  • 33
  • 43
  • 1
    What operation is causing this error? You need to debug your code to isolate what is causing this. Also, where are you calling `ini_set('memory_limit', '512M');`, local machine? hosted site? – Jake N Sep 20 '10 at 07:42

3 Answers3

4

Do you have access to the php.ini file? Then change the memory_limit value there.

You should also analyze your script. Lots of database transactions? Many of them in loops? Lots of loops? Lots of temporary variables? A clever usage of unset can make a huge difference.

Also nice to know: Performance Considerations and Garbage Collection

Edit (a possible answer to your question why memory_limit doesn't work with ini_set)

memory_limit integer 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.

source: php.net

teemitzitrone
  • 2,250
  • 17
  • 15
3

That's crashing after about 42M, which suggests to me that the PHP interpreter didn't get the memo. Try the same ini_set() in a test page with the phpinfo() output and look for the memory limit.

Can you set it in the php.ini file instead?

John Franklin
  • 4,962
  • 1
  • 23
  • 27
0

I was having a similar issue earlier. In my case it was the suhosin patch preventing my script from acquiring more memory.

Community
  • 1
  • 1
soulmerge
  • 73,842
  • 19
  • 118
  • 155