Page 1 of 1

Out of memory with plenty of memory...

Posted: Sat Jul 05, 2008 4:00 pm
by RealityRipple
Hello all! I've got a problem dealing with dynamically creating a compressed file (ZIP) using some possibly large files. The exact code that I use to create the file shouldn't be important, as it's mostly the error that confuses me:
Fatal error: Out of memory (allocated 30146560) (tried to allocate 4302599 bytes) in /homepages/1/d115845883/htdocs/software/freeware/RCB/hashes/zip.php on line 60
Pretty straightforward, you'd think. The problem is, according to phpinfo(), memory_limit is set to 40M. I'm guessing there's a specific way to allow a script access to all 40 MB, but I sure don't know it. If you need me to post anything, I will, but I'm hoping there's a simple answer to this...


Edit: Huh, I seem to have fixed it by changing

Code: Select all

 $archiveData = $data.
   $controlDirectory.
   $this -> endOfCentralDirectory.
   pack("v", sizeof($this -> centralDirectory)).
   pack("v", sizeof($this -> centralDirectory)).
   pack("V", strlen($controlDirectory)).
   pack("V", strlen($data)).
   "\x00\x00";
into

Code: Select all

 $archiveData = $data;
  $archiveData.= $controlDirectory;
  $archiveData.= $this -> endOfCentralDirectory;
  $archiveData.= pack("v", sizeof($this -> centralDirectory));
  $archiveData.= pack("v", sizeof($this -> centralDirectory));
  $archiveData.= pack("V", strlen($controlDirectory));
  $archiveData.= pack("V", strlen($data));
  $archiveData.= "\x00\x00";
Go figure.

Re: Out of memory with plenty of memory...

Posted: Sat Jul 05, 2008 4:53 pm
by jaoudestudios
I had the same problem with resizing large images.

In the php.ini file you need to increase the memory allocation and it will solve the problem.

Re: Out of memory with plenty of memory...

Posted: Sat Jul 05, 2008 6:44 pm
by koen.h
You can also use ini_set('memory_limit','40M');

Re: Out of memory with plenty of memory...

Posted: Sat Jul 05, 2008 6:48 pm
by jaoudestudios
I dont think that will work, it wont be able to increase passed the php.ini file, but might be able to decrease it.

I would go straight to the source.

But if you do get it to work koen.h way, then I would be interested to know, as I tried it before and had no joy so sorted it all through the php.ini

Re: Out of memory with plenty of memory...

Posted: Sat Jul 05, 2008 6:55 pm
by Eran
According to the manual the 'memory_limit' option is defined as PHP_INI_ALL, which means it can be set using the set_ini() function. Whether it can actually control the memory allocation at run-time, that difficult to say