php.htaccessmysqlimemory-limitphp-mysqlidb

Allowed memory size


I'm using PHP MySQLi Database Class and on my local computer everything works without any problem. However, when I upload my project to my host I get the following error:

Fatal error: Allowed memory size of 52428800 bytes exhausted (tried to allocate 50331646 bytes) in /usr/home/data/site/public_html/classes/MysqliDb.php on line 678

Line 678 from MysqliDB.php contains the following command:

call_user_func_array(array($stmt, 'bind_result')`, $parameters);

When I type php_value memory_limit 64M in .htaccess file I get this error:

[Fri May 30 11:03:18 2014] [alert] [client 37.98.159.18] /usr/home/data/site/public_html/.htaccess: Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration, referer: http://example.org/index.php


Solution

    1. Check out the PHP version and - especially - if mysqli on the host is mysqlnd-based. You can use phpinfo() for this. Change host if it's not.
    2. Don't be greedy in your database table definitions. If you need to store only a page of text, do not define your column as a longblob, make it modest text - earlier versions of mysqli tried to allocate memory for the maximum possible size based on the row definition, not the real data size.
    3. If your query returns way too much rows, and you need all of them, making your query unbuffered will solve the problem.