php memory_limit

php memory_limit

Posted by: blackeye
Posted on: 2007-03-17 08:53:00

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?

Re: php memory_limit

Posted by: Mousee
Posted on: 2007-03-17 12:05:00

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 smile

Re: php memory_limit

Posted by: blackeye
Posted on: 2007-03-17 13:50:00

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.

Re: php memory_limit

Posted by: Mousee
Posted on: 2007-03-17 14:04:00

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:

In reply to:


<?
phpinfo()
?>



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 :/
That would at least explain why it's ignoring your settings though...

Re: php memory_limit

Posted by: blackeye
Posted on: 2007-03-17 14:26:00

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.

Re: php memory_limit

Posted by: Mousee
Posted on: 2007-03-17 15:41:00

Oye.. copied the wrong post here.. too much math lately! tongue

Yah I saw your mention of phpinfo originally, I just wanted to be sure it was pointing to the right install of php 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.Edited by Mousee on 03/17/07 04:27 PM (server time).

Re: php memory_limit

Posted by: rlparker
Posted on: 2007-03-17 18:28:00

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

Re: php memory_limit

Posted by: JAugusto
Posted on: 2007-08-27 17:54:00

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.

Tags: memory limitphpinfowikiserver memoryini filephp scriptphp5allocatefatal error