It is amazing that anyone can figure this stuff out. The long and short is that I’ve been using Zenphoto with great success for photos. But when I got my new Canon 5D Mark II, suddenly, images started failing. You can see the blanks in ZenPhoto Troubleshooting say in that you need 41MB of PHP allocated memory to process an 8 megapixel image, but with a 21 megapixel, you more than 4x that. Or more like 200MB.

In this day and age of gigantic 2-4GB server memory, you wouldn’t think that is a problem. But how to figure out what Bluehost.com allocates? Another google search shows that at Vivvo.net, you have to stick a tiny file up there that calls PHP and asks it. The error you get is in your error log as:

[02-Feb-2009 21:45:49] PHP Fatal error: Allowed memory size of 100663296 bytes exhausted (tried to allocate 22464 bytes) in /home2/richtong/public_html/gallery/zp-core/functions-image.php on line 70

And the code to check it is

<?php echo ini_get(‘memory_limit’);
?>

In my case, this reports that 128MB is allocated which is pretty close to the 100MB that reports failure in the error message.

On bluehost, the php.ini files is located at ~/public_html/php.ini and the code you add is a simple

memory_limit = 256M;

Teknobites.com says that you can fix this by adding this line into the .htaccess in your zenphoto root

php_value memory_limit 256M

But I’m finding that when I start zenphoto, it reports maximum memory at 96MB even though my own script reports it is 256M as I set it with php.ini. So obviously, somewhere zenphoto is changing this. Arrgh!

Laperolog.com
and the official Zenphoto has a changelog which indicates in version 1.0.4 in 2006, they added a ini_set parameter to go to 96M, so it is in there somewhere! So where is it? Had to download zenphoto and do a search for it manually. And I found it in functions-basic.php and the line is (for those of you who don’t read php and this is Drupal, parse_size takes the 96M that ini_get of memory limit returns and converts it into a long integer. But of course, I’m wondering now if this is failing because at 256MB or so, the function isn’t working.

<blockquote>// Set the memory limit higher just in case — suppress errors if user doesn’t have control.
// 100663296 bytes = 96M
if (ini_get(‘memory_limit’) && parse_size(ini_get(‘memory_limit’)) < 100663296) {
    @ini_set(‘memory_limit’,’96M’);
}</blockquote>

But when I comment this out I get the answer which is 32M is allocated which indicates that somewhere Bluehost is overriding my php.ini from 256MB to 32MB. OK, so let’s try the .htaccess trick and if that fails a manual edit of the function is needed. This seemed to work when I query the admin but when I try to image, I get the same error aboiut allocation which fails at 96M. Feels like somehow I have to reload a function or something.

More spelunking reveals that in the root directory of /public_html, the php.ini file is from there, but from zenphoto, it changes, the php.ini is from /usr/local/lib.php.ini which has a default of 32M and shoving a php.ini file there with 256M as the limit seems to fix this so that every folder can have its own php.ini which is kind of cool which you have to put in zp-core and this finally works.

So the solution is to add the file into /zenphoto installation root/zp-core/php.ini

<blockquote>
memory_limit = 256M;
</blockquote>

I’ve no idea why this works, but just changing the ini_set didn’t, but here is the fix.

I’m Rich & Co.

Welcome to Tongfamily, our cozy corner of the internet dedicated to all things technology and interesting. Here, we invite you to join us on a journey of tips, tricks, and traps. Let’s get geeky!

Let’s connect

Recent posts

Loading Mastodon feed…