views:

1288

answers:

3

I have my own php data object class that wraps the mysqli library. It works fine handling most datatypes, including text. As soon as I change a table column from text to mediumtext, I get the error described in the title of this question. I've tested my php scripts on several shared hosting environments, and I only get this error on one of them.

Does the MediumText and LongText really use up that much memory?

I will start optimizing my php classes, but I want to make sure I'm on the right track..

+3  A: 

mediumtext can hold up to 16777215 as specified in http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html

This would appear to be > than you memory limit as defined by php. So it makes sense.

Mike B
+2  A: 

The mediumtext and longtext fields could, potentially, hold that much information. Are you just changing the column type, or are you changing the column type then jamming it full of text? If it's the former, my guess would be that there's some run away loop/recursion that's building up a bunch of objects/arrays/somethings and you're hitting PHP's default memory ceiling.

You can control the amount of memory allocated to PHP via php.ini, or you can use the ini_set function to set the values at run-time.

ini_set("memory_limit","12M");
Alan Storm
thanks, i put it at 20M and everything worked fine! I was surprised shared hosting would allow me to request more memory like that....I suppose there's a limit to the amount of memory I can squeeze out of ini_set()?
John
Most shared hosting is run by a cabal of marketers and/or business men who don't know, or care, much about the technical details (which is why it's so unreliable). Well run shared hosts will have monitors in place that will kill off and process that starts consuming too much memory.
Alan Storm
memory_limit itself should be, in theory, limited only to the memory currently available on the box.
Alan Storm
+1  A: 

That hosting provider probably has PHP set to only allow a script 8 megabytes of memory.

memory_limit = 8M ; Maximum amount of memory a script may consume

You can check what this is set to using phpinfo(), create a script with the following, upload it and point your web browser at it (make sure you remove it once done as it gives away potentially sensitive information):

<?php

phpinfo()

?>

Look for "memory_limit" towards the bottom. If it's set to 8 megabytes that's your problem.

Kurt