ini_set('memory_limit')

ini_set('memory_limit')

Postby joepublick » Mon Jan 28, 2008 4:53 pm

Hello,

I have a PHP/MySQL-based site with a considerable number of photos and videos that can be uploaded by members. When an image is uploaded to my site, it gets resized 3 times using the GD library, to create a thumbnail, a postcard, and a desktop-sized version. I've been having sporadic problems with a fatal error resulting from the memory_limit of 36 megs. The images that cause the error are always high-resolution images. I know WHY the error is occurring - the image dimensions are too large and thus consuming too much RAM. Example: a 1600x1200 image with a bit depth of 24 requires almost 47 megs of RAM for resizing (1600x1200x24 = 46,080,000)

I've taken steps to address this, including:

ini_set('memory_limit', '64M')

This should theoretically up the RAM to 64megs to accomodate the 1600x1200 image I mentioned. But it's not working. Even though phpinfo() shows the memory is set at 64megs, it still doesn't work. The file transfer to the server works fine, though!

So...

1) does ini_set('memory_limit', 'xxM') actually work, or are we blocked from changing memory limits?

2) are we generally prohibited from changing system settings such as this?

Any suggestions as to how I might accomodate high-resolution images besides just throwing back an error at the user telling them to manually resize first?
joepublick
 
Posts: 3
Joined: Wed Aug 29, 2007 3:42 pm

Re: ini_set('memory_limit')

Postby jeffrey » Mon Jan 28, 2008 5:29 pm

Hello,

You can try putting a php.ini file in the particular directory of your web site where you want the memory_limit value increased. In the php.ini file you just need to have the custom PHP setting you want, ie.,

memory_limit = 64M

Please note that doing so will only enable that setting for the directory containing the php.ini file and not for sub-directories. If you continue to have problems you can always send an email to support@canadianwebhosting.com explaining your issue so that we may look into it in further detail.

Regards,
Jeffrey
jeffrey
 

Re: ini_set('memory_limit')

Postby joepublick » Mon Jan 28, 2008 6:51 pm

jeffrey wrote:Hello,

You can try putting a php.ini file in the particular directory of your web site where you want the memory_limit value increased. In the php.ini file you just need to have the custom PHP setting you want, ie.,

memory_limit = 64M

Please note that doing so will only enable that setting for the directory containing the php.ini file and not for sub-directories. If you continue to have problems you can always send an email to support@canadianwebhosting.com explaining your issue so that we may look into it in further detail.

Regards,
Jeffrey


Thanks for the very quick reply. I figured out a slightly different approach by setting the memory_limit in code using PHP's ini_set, just before I process the image. Seems to work. But what's the maximum memory_limit that's allowable? If memory_limit represents RAM memory, surely we're not allowed to set it to whatever value we want??

Appreciate the help. Very impressed with the service, quality, and ease of use of Canadian Web Hosting.
joepublick
 
Posts: 3
Joined: Wed Aug 29, 2007 3:42 pm

Postby sanoop » Wed Jan 30, 2008 1:12 am

Memory limit is the maximum amount of memory in bytes that a script is allowed to allocate. It prevents poorly written scripts from consuming all available memory in the server.

In shared servers, we can set memory limit upto 64m. But in dedicated servers or VPS, you can increase the value upto your requirement.
sanoop
 

Postby joepublick » Wed Jan 30, 2008 11:13 am

sanoop wrote:In shared servers, we can set memory limit upto 64m. But in dedicated servers or VPS, you can increase the value upto your requirement.


That's what I was looking for. Thanks for the info.
joepublick
 
Posts: 3
Joined: Wed Aug 29, 2007 3:42 pm


Return to PHP

Who is online

Users browsing this forum: No registered users and 1 guest