简体   繁体   中英

Mysql MediumText causes PHP Fatal error: Allowed memory size of 8388608 bytes exhausted

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..

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.

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");

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM