Php memory_limit

software development

#1

I keep getting the following error when trying to run a particular php script:
Fatal error: Out of memory (allocated 76283904) (tried to allocate 2 bytes) in …

First I tried to use set_ini within my script to change memory_limit, but I kept getting the error. Then I followed the wiki instructions to install php5. It completed and I edited the php.ini file to set the memory_limit well above this value. phpinfo() confirms that the memory limit is what I set it to. Running the script still produces the error. I’m not hitting the limit I set, so what limit am I hitting? Is this a server memory limit?


#2

76megs is quite a lot of memory you “think” you need to use. If you’re just uploading files using PHP, then I can understand that, but do you really need to use PHP to upload a file of that size? There is FTP and other such scripts that don’t use PHP to accomplish the same thing.
Anyways, considering the shared environment you’re in, that’s one ugly script either way. Hopefully you don’t intend to use it often, heh.

Since you really didn’t say what you changed the value of “memory_limit” to, nor did you explain what exactly this script is attempting to do (upload files? parse some kind of data? what exactly?), I can’t really help you any further other than to suggest increasing the limit you’ve currently set. Give me some more info and I’ll try and see if I can help you figure it out :slight_smile:


#3

Well no matter what limit I set, I get the same exact error at the same amount of memory allocated. I am actually uploading and parsing data. I’m using an array of bytes, and it seems php was allocating much more memory than needed. I changed the code to use a string and it works now.

This is just an example of the method I was using. It’s just a 1024x1024 array. This example causes the error.

<?php $var=array(); for($x=0; $x<1024; $x++) { for($y=0; $y<1024; $y++) { $var[$x][$y]=chr(0); } } ?>

I changed it to use a string like this:

<?php $var=str_repeat(chr(0),1024*1024); for($x=0; $x<1024; $x++) { for($y=0; $y<1024; $y++) { $var{($y*1024)+$x}=chr(0); } } ?>

Of course that still doesn’t explain why the limit I set wasn’t reached.


#4

It almost sounds like you’re not using the custom install of PHP at all. Or if anything, it’s at least not seeing your php.ini file.

Try to create a basic php with:

The output, as I’m sure you’re aware of what it does, should tell you the location of PHP that it’s currently using.
If it’s not pointing at your own php install, then something went wrong :confused:
That would at least explain why it’s ignoring your settings though…


#5

Like I said in the initial post, phpinfo() reflects the limit I set in php.ini and is pointing to the version I installed. If I change the limit in php.ini, it shows up in phpinfo(). The main problem was getting the script working, and I figured it out now. I’m not too worried about the memory limit issue, but it still would be nice to know why it’s happening.


#6

Oye… copied the wrong post here… too much math lately! :stuck_out_tongue:

Yah I saw your mention of phpinfo originally, I just wanted to be sure it was pointing to the right install of php :slight_smile:
Anyways … yah. No idea why it’s not following a higher specified value. Almost seems like it’s hitting a memory limit of the server itself… like a userspace memory limit? I dunno. Weird.


#7

I suspect that Dreamhost’s procwatch program might be involved. It kicks in and kills stuff that is either too memory intensive, run too long, or too cpu intensive, as determined by Dreamhost’s unpublished metrics. :wink:

–rlparker


#8

I agree. Changing php.ini does nothing. Limit is 8M!

I have a big xml file (25Mb) to process using a complex algorith in php and can’t do it otherway…

Yesterday limit was higher and I managed to process it once, but I need to process 10 more times.

Thanks in advance for any help.


#9

How can I increase the PHP memory limit 96M

Please help me, thanks!


#10

96 Megs is quite a bit, but you can try a modified php.ini file. However, if you have a process (or more) that’s hogging memory, it may get killed by a process watcher on the server and you may get notified by Support to cut back on your memory usage.

http://sxi.sabrextreme.com/phpini