Kobus Myburgh
Kobus Myburgh

Reputation: 1202

PHP Memory Limit - using less memory than the limit, but still error occurs

I have a strange memory limit issue in PHP. I have to read a lot of data into an array using a particular script, and I keep running out of memory.

My memory is now at 2048M in the php.ini file, and phpinfo() indicates it as such, yet, I keep getting this error:

Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 142610432 bytes) in ... on line 173

Now - those two total about 680MB. This is far below the limit I set it to. Why would this error still occur?

Upvotes: 1

Views: 583

Answers (1)

angel.bonev
angel.bonev

Reputation: 2242

Try using ini_set

Sets the value of the given configuration option. The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.

ini_set("memory_limit" , "2048M"); 

In most cases ini_set rewrites all other PHP configurations

Upvotes: 1

Related Questions