Welcome Guest, Not a member yet? Register   Sign In
Allowed memory size
#1

Hi,

i use smarty 4 and fetched 600 Database entries ($model->findAll()) and wanted to show it in the browser. I get only the message Allowed memory size of xxxxxxx bytes exhausted. The same if i increase the memory limit.
By not using smarty it is the same problem. Is there a solution?
Reply
#2

Increase the memory limit.

How big is the data size of the 600 Database entries?
Reply
#3

(This post was last modified: 07-09-2022, 05:36 PM by groovebird.)

(07-09-2022, 05:19 PM)kenjis Wrote: Increase the memory limit.

How big is the data size of the 600 Database entries?

I did increase the memory limit (3 GB) but it has no effect. In CI 3 i had never such problems with 1 GB of memory. Why need codeigniter so much memory? I reduced the limit to 100 entries but the same problem. My entries for testing is the normal posts table from wordpress but also with other tables it is the same problem. It is a fresh installation. I also removed smarty but can't get it to work. For the model i use as returnType the classname. As long as i do not output something it is not a problem but assigning and showing a variable in the template does not work.
Reply
#4

(This post was last modified: 07-10-2022, 12:00 AM by InsiteFX.)

Code:
// place in your index.php file
ini_set('memory_limit', '256MB');
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

How about using chunks?
https://codeigniter4.github.io/CodeIgnit...ts-of-data
Reply
#6

Definitely do some memory optimizations, like chunking, because even 1 GB is a tremendous amount of memory for a single page load. If I had to guess though I’d say you are in development environment with the debug toolbar running, and that can be a huge memory drain since it gathers all database returns and variables and usage history. Try turning off the toolbar or switch environment to production and see if that prevents the errors.
Reply
#7

(07-14-2022, 03:56 AM)MGatner Wrote: Definitely do some memory optimizations, like chunking, because even 1 GB is a tremendous amount of memory for a single page load. If I had to guess though I’d say you are in development environment with the debug toolbar running, and that can be a huge memory drain since it gathers all database returns and variables and usage history. Try turning off the toolbar or switch environment to production and see if that prevents the errors.

You are right, i have the debug toolbar open. Even with a fresh installation and only a single query i want to var_dump the results, this error occurs.

What do you mean with chunking and memory optimizations? what can i do with a fresh installation?
Reply
#8

See Paul’s link on how to chunk database results - basically you only draw from the database in smaller increments and process them in “chunks” so you don’t have to hold it all in memory at once. There are lots of other ways to optimize memory that aren’t specific to CodeIgniter (or even PHP) and the appropriate solution for you will depend on exactly what you are trying to do. I’m not familiar with Smarty but I would venture to say that in a regular web app you should never be trying to process 600 rows from a database in one go. Look into data streams, PHP generators, grouped database transactions, caching… any techniques that will give you more tools to downscale your memory needs.
Reply
#9

(This post was last modified: 07-14-2022, 05:03 AM by groovebird.)

(07-14-2022, 04:15 AM)MGatner Wrote: See Paul’s link on how to chunk database results - basically you only draw from the database in smaller increments and process them in “chunks” so you don’t have to hold it all in memory at once. There are lots of other ways to optimize memory that aren’t specific to CodeIgniter (or even PHP) and the appropriate solution for you will depend on exactly what you are trying to do. I’m not familiar with Smarty but I would venture to say that in a regular web app you should never be trying to process 600 rows from a database in one go. Look into data streams, PHP generators, grouped database  transactions, caching… any techniques that will give you more tools to downscale your memory needs.

600 rows was only a test, but a fresh CI4 install (no smarty) should't give me this error i think. I generally wonder why i get this error. Also by fetching 50 rows this is a problem. It is also not a problem to fetch this rows from the database but the output is the problem (a var_dump crashes, an not defined variable in smarty show this issue). This is the same app i want to migrate to CI4. In years before with CI3 a have never seen this error.
Reply
#10

If the required memory is more than the currently available memory, it is natural that errors will occur.
CI4 is not CI3. You are free to think that errors should not occur, but unfortunately, if there is not enough memory, errors will occur.

Either increase the amount of available memory or decrease the amount of memory used.
Probably all you need to do is to do some memory optimizations.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB