Welcome Guest, Not a member yet? Register   Sign In
Memory exhausted error for a few records
#1

I am encountering this error: 
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 8192 bytes) in /var/www/html/lgudms2/system/database/drivers/mysqli/mysqli_result.php on line 214

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32768 bytes) in /var/www/html/lgudms2/application/views/errors/html/error_php.php on line 1

This happens when I try to load a method that makes around 5 to six mysql queries to load different records for purposes of access control and loading related encrypted data. 
This error (and others like it) only started about two weeks ago, so I'm thinking (without any basis) if the size of the database  (currently about 200+ MB) is a factor. 

I would account the queries as: 

  1. Method within the same class - Check if the current user is allowed to access the method. The user's id is stored in the session. 
  2. Method to check if the code from the URL is valid
  3. Method to get the data from table1 based on the code (62 columns, majority of columns are varbinary(1000) for encrypted AES_ENCRYPT)
  4. Method to get related data based on foreign key from table2 (14 columns, about half of the columns are varbinary(1000) for encrypted AES_ENCRYPT)
  5. Method to get related data based on foreign key from table 3  (14 columns, majority of the columns are varbinary(1000) for encrypted AES_ENCRYPT)
  6. Method to get related data based on foreign key from table 4  (15 columns, about half of the columns are varbinary(1000) for encrypted AES_ENCRYPT)
In between queries 3,4,5 and 6, I have some processing  that check the retrieved data if they are from this date, or if they are present (they will be redirected if not), and something like that. 


I tried my code for a version of the mysql with less record, with data (of similar tables and relationships) from about a month ago, and I don't encounter the problem I encounter compared with the data I have from recently. I have to refresh the page about 2 or 3 times for the method to go through. 

As for my database.php file, I have already set save_queries to FALSE.

My current solution is to set the memory limit to 256M, but I feel that this is not the proper solution. 

Would appreciate solution that would identify where the memory size is increased, and how to resolve it. Thank you.
Reply
#2

@rbulalakaw ,

How efficient are the queries? Are the queries slow? Have you done an analysis of the queries?
Reply
#3

(This post was last modified: 08-27-2021, 01:36 AM by InsiteFX.)

You could also try freeing the database query result before continuing on to the next query.

PHP Code:
// CodeIgniter 4
$query->freeResult(); // The $query result object will no longer be available

// MySQLi
mysql_free_result($result); 

Try that.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB