EllisLab text mark
Advanced Search
     
Changing memory size on a single page in CodeIgniter
Posted: 29 July 2007 04:00 PM
Avatar
Joined: 2007-07-19
18 posts

I’m playing around with the image manipulation class, and I’m running into the well known “Allowed memory size of 8388608 bytes exhausted…” error. I was wondering what the best way to temprarily change this value is. I’m only resizing an image when the visitor uploads one that’s too big, so setting the maximum to 32MB for *every* page seems overkill.

What is the best way to do this in CodeIgniter for *just* the upload-page?

 
Posted: 29 July 2007 04:13 PM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2006-06-23
370 posts

PHP 5’s default memory_size limit is 128MB. I would recommend upgrading to PHP5 for the improved memory management or not worry about the 32MB limit you currently have.

To answer your question, put this into the function where it’s needed:

ini_set('memory_limit''32M'); 

That will change the memory limit temporarily.

 Signature 

Mac OS X 10.8, Apache 2.x, NGiNX, PHP 5.4.x, CodeIgniter 1.7.2/2.1.3

 
Posted: 29 July 2007 07:03 PM   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2007-07-19
18 posts
coolfactor - 29 July 2007 08:13 PM

PHP 5’s default memory_size limit is 128MB. I would recommend upgrading to PHP5 for the improved memory management or not worry about the 32MB limit you currently have.

To answer your question, put this into the function where it’s needed:

ini_set('memory_limit''32M'); 

That will change the memory limit temporarily.

Thanks for your reply! I’m actually running PHP5 (through AppServ on Windows)but it still gave the error. I will be using a live server with PHP5, I’ll check if that has the bigger memory limit.

Is it necessary to put the memory_limit back to default after resizing?

 
Posted: 29 July 2007 07:11 PM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2006-06-23
370 posts
See64 - 29 July 2007 11:03 PM

Is it necessary to put the memory_limit back to default after resizing?

No. Setting it using ini_set() only changes it temporarily for that one page request. It’s back to its default for the next page load.

 Signature 

Mac OS X 10.8, Apache 2.x, NGiNX, PHP 5.4.x, CodeIgniter 1.7.2/2.1.3