1

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

Dharman
  • 30,962
  • 25
  • 85
  • 135
Abduhafiz
  • 3,318
  • 5
  • 38
  • 48
  • this might help you - http://stackoverflow.com/questions/8812154/overriding-php-ini-on-server – prava May 30 '14 at 06:11
  • it seems you tried to fetch all content at once, it easy drown out the memory, just fetch each row and process instead – Hieu Vo May 30 '14 at 06:56

2 Answers2

4
  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.
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
-1

The cause is because PHP has exhausted the maximum memory limit as set by the configuration value memory_limit.

Typically this PHP configuration value has a very low default of 8MB or 16MB.

So, Increase the memory_limit in the servers php.ini configuration file. You can simply change this value from 64MB to 256M or 512MB depending on your needs(Lesser the size is better).

configuration in php.ini file

memory_limit = 128M
max_execution_time = 19000

Another option is to increase this via .htaccess file to solve this problem. so it should be like below :

php_value memory_limit 128M 
php_value max_execution_time 19000