Fatal error: Allowed memory size of xxxbytes exhausted |
HI,
I am getting this error: Code: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in /home/mywhdms/public_html/am/system/database/drivers/pdo/pdo_result.php on line 195 I am using CodeIgniter V3 and DB Driver is PDO. Trying to retrieve 25000 records for calculation of values. My DB Settings are as follows : Code: $active_group = 'default';
You PHP settings has a maximum amount of memory set for each PHP request. In your case 128 MB. Your code/query need more memory to run completely then PHP has to offer. Basicly the script stops executing as soon as the limit is reached.
To resolve you can 1) alter the setting inside php.ini: memory_limit: 256M. Some hosts (not all) let you alter this setting through .htaccess or inside you PHP script. You can check google for the correct syntax. 2) You can optimize your own code and queries so it can run the whole script without hitting the current limit of 128 MB. For example, be selective in your query, don't use "SELECT * FROM X" if you only need 2 columns.
(09-10-2015, 02:38 AM)Narf Wrote: ... and if there's another way, don't fetch 25k rows in the first place. Actually its an activity table, so I need to calculate total number of activity happened, like xx Success, xx Pending and so on. Actually site traffic increased in just 2 days , now today number of records are almost 70000, can you suggest me any work around. Currently just in mess to figure-out how to handle that.
http://www.codeigniter.com/user_guide/da...esult-rows
Read about unbuffered_row() method. Edit: Or if you need only sums or counts, then if it is possible let the SQL server do them.
in any circumstance you should prevent calculations like that in PHP
most of the time if you want to calculate something like that with this type of data you should think about triggers MYSQL Trigger Doku Basically you can set after and before triggers in order to react with your action. Allowed are, on update, on insert and on delete triggers.
If you just want the counts, use $this->db->count_all() or $this->db->count_all_results().
If you need both, you should probably use one of the above functions for the count and page the actual data.
If can't just make a "select count" and you really need the data for each rows to make your stats, select only the columns you need and set save_queries to FALSE in database configuration. Depending on how much query you make, it can use a lot of memory. I can't find it anywhere in the user guide, but it should be set to FALSE in production!
From the config/database.php file : PHP Code: | ['save_queries'] TRUE/FALSE - Whether to "save" all executed queries.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Hi,
Thanks for the replies, but currently issue is the still same: What I have done: 1-Changed memory limit to : 256M in php ini 2- Corrected maxm. queries to use unbuffered_row() method. What I observed: 1-If I am changing DB drivers to mysqli its working fine. 2-if I am setting it to PDO same error is coming. i.e. Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 12288 bytes) in /home/xxxx/public_html/am/application/modules/clients/views/view.php on line 103 Is there any work around for PDO to work fine? If so, can you people guide me.
(10-19-2015, 05:55 AM)chandrabhanu Wrote: 1-Changed memory limit to : 256M in php ini Then you're still limited to 128MB and not 256MB. You need to restart Apache for your change to take effect. ...and, did you set save_queries to false ?
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/ |
Welcome Guest, Not a member yet? Register Sign In |