Out of memory with plenty of memory...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
RealityRipple
Forum Newbie
Posts: 1
Joined: Sat Jul 05, 2008 3:51 pm
Location: Nipomo, California
Contact:

Out of memory with plenty of memory...

Post 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.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

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

Post 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.
koen.h
Forum Contributor
Posts: 268
Joined: Sat May 03, 2008 8:43 am

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

Post by koen.h »

You can also use ini_set('memory_limit','40M');
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

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

Post 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
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

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

Post 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
Post Reply