<p>I'm building a webtoon with CraftCMS 4 but facing this issue: <code>SQLSTATE[HY000]: General error: 5 Out of memory (Needed 418490224 bytes)</code></p>
<p>Screenshot: <a href="https://i.sstatic.net/oMKud.png" rel="nofollow noreferrer">https://i.sstatic.net/oMKud.png</a></p>
<p>All entries are a Structure section. Two types of story: series and single. The series include child entries (level 2, chapters). Here is how I display the nested entries on pages.</p>
<p>On home/category/search page, I display parent entries <code>{% paginate craft.entries().section('stories').level(1).limit(24).orderBy('dateUpdated desc') as pageInfo, pageEntries %}</code>.
Each parent entry has the number of the latest chapter <code>{% set num = entry.children().level(2).orderBy('id desc').one() %}</code></p>
<p>Demo entries: <a href="https://i.sstatic.net/CJxg7.png" rel="nofollow noreferrer">https://i.sstatic.net/CJxg7.png</a></p>
<p>When reading a story (series), click the parent entry link where I show child entry titles (chapters) <code>{% set craft.entries().section('stories').level(2).orderBy('id desc').all() %}</code> Click each chapter to read. On each chapter page, I show all chapters of a parent entry and show related parent entries, for example, newest or hot entries.</p>
<p>I use <code>{% cache for 5 minutes %}</code> for all loops <code>{% for %}</code> but the issue is still available. What should I do to fix it? Does Redis cache work? If yes, can you show me step by step to install it? I found this <a href="https://craftcms.com/docs/3.x/config/#memcached-example" rel="nofollow noreferrer">guide on CraftCMS 3 docs</a> but I don't know how to set it.  Which folder will I install the <code>yii2-redis</code> library? Run composer in the root folder of Craft or somewhere?</p>
<p>Thanks for your answer!
P/s: I'm, a web builder, not knowledgeable about coding without the detailed guides or samples. I like CraftCMS because of twig templates. It's easy to code.</p>

CC BY-SA 4.0
2023-04-03T03:02:51.283Z
Sounds like the underlying MySQL server has run out of memory. What sort of environment are you getting this on... locally? Usual MAMP, DDEV, etc.?
Brad Bell
CC BY-SA 4.0
2023-04-03T05:26:34.100Z
It's on production environment, DigitalOcean 1GB RAM, Maria DB. I'm not sure if I build the web in the wrong way, so there are many requests to the database and make this error happen. If this issue is about the limitation of my server, what should I do?
Alex
CC BY-SA 4.0
2023-04-03T14:13:05.193Z
If you bump the VM to 2GB, can you reproduce the error?
Brad Bell
CC BY-SA 4.0
2023-04-04T02:40:38.827Z
I'm unable to upgrade my managed vps this time. I've contacted the provider about this issue, and they increased the memory limit of PHP to 512MB, wait time, etc. The error is still happening. I found this article https://craftcms.com/knowledge-base/query-batching-batch-each

I think it may refer to my issue due to large data set. I also enabled `CRAFT_DB_USE_UNBUFFERED_CONNECTIONS=true` in the file .env as stated in this guide (https://craftcms.com/docs/4.x/config/db.html#useunbufferedconnections)
Alex
CC BY-SA 4.0
2023-04-04T02:58:42.510Z
When I added new child entries in the CraftCMS admin, viewed the web and the error happened sometimes.

In general, I tried some ways: eager-loading `with(['image_field'])` to fetch entries, unbuffered database connection (just found the article and enabled it in the file .env), `{% cache for 5 minutes %}` tag for loops, PHP memory limit expansion (512MB, RAM 1GB). That's it.
Alex
CC BY-SA 4.0
2023-04-04T04:44:48.417Z
The error happened again with more bytes https://i.imgur.com/qXy0oTM.png
Alex
CC BY-SA 4.0
2023-04-04T18:20:57.977Z
My theory is (based on the error message) that the VM is running out of memory. 1GB VM, you figure the OS and system libraries take up 400-500MB. Web server and database could take up another 200-300MB, which doesn't leave a lot left to process heavy-handed PHP and database requests (especially large ones).
Brad Bell
CC BY-SA 4.0
2023-04-08T10:33:54.650Z
I hope this error is due to out of memory only. I noted there are more bytes after creating new entries. Can you tell me if there is any problem how I'm building the web? Something wrong related to technical issues? Or lots of requests to database? Is there any better way to decrease the number of requests to database? For example, use Element API to create the entry API (get all child entries), then use Feed Me plugin to fetch and show all child entries by the parent entry. Please share your ideas how to build a better webtoon (requests, performance, etc). Thanks so much.
Alex
<cache><error><mysql><craft4><redis>
SQLSTATE[HY000]: General error: 5 Out of memory (Needed 418490224 bytes)
# SQLSTATE[HY000]: General error: 5 Out of memory (Needed 418490224 bytes)

(Asked by: username_0 on 2023-04-01)

I'm building a webtoon with CraftCMS 4 but facing this issue: `SQLSTATE[HY000]: General error: 5 Out of memory (Needed 418490224 bytes)`

Screenshot: <https://i.sstatic.net/oMKud.png>

All entries are a Structure section. Two types of story: series and single. The series include child entries (level 2, chapters). Here is how I display the nested entries on pages.

On home/category/search page, I display parent entries `{% paginate craft.entries().section('stories').level(1).limit(24).orderBy('dateUpdated desc') as pageInfo, pageEntries %}`.
Each parent entry has the number of the latest chapter `{% set num = entry.children().level(2).orderBy('id desc').one() %}`

Demo entries: <https://i.sstatic.net/CJxg7.png>

When reading a story (series), click the parent entry link where I show child entry titles (chapters) `{% set craft.entries().section('stories').level(2).orderBy('id desc').all() %}` Click each chapter to read. On each chapter page, I show all chapters of a parent entry and show related parent entries, for example, newest or hot entries.

I use `{% cache for 5 minutes %}` for all loops `{% for %}` but the issue is still available. What should I do to fix it? Does Redis cache work? If yes, can you show me step by step to install it? I found this [guide on CraftCMS 3 docs](https://craftcms.com/docs/3.x/config/#memcached-example) but I don't know how to set it. Which folder will I install the `yii2-redis` library? Run composer in the root folder of Craft or somewhere?

Thanks for your answer!
P/s: I'm, a web builder, not knowledgeable about coding without the detailed guides or samples. I like CraftCMS because of twig templates. It's easy to code.

**Tags:** cache, error, mysql, craft4, redis
> **Comments:**
> **username_1**: Sounds like the underlying MySQL server has run out of memory. What sort of environment are you getting this on... locally? Usual MAMP, DDEV, etc.?  
> **username_0**: It's on production environment, DigitalOcean 1GB RAM, Maria DB. I'm not sure if I build the web in the wrong way, so there are many requests to the database and make this error happen. If this issue is about the limitation of my server, what should I do?  
> **username_1**: If you bump the VM to 2GB, can you reproduce the error?  
> **username_0**: I'm unable to upgrade my managed vps this time. I've contacted the provider about this issue, and they increased the memory limit of PHP to 512MB, wait time, etc. The error is still happening. I found this article https://craftcms.com/knowledge-base/query-batching-batch-each  I think it may refer to my issue due to large data set. I also enabled `CRAFT_DB_USE_UNBUFFERED_CONNECTIONS=true` in the file .env as stated in this guide (https://craftcms.com/docs/4.x/config/db.html#useunbufferedconnections)  
> **username_0**: When I added new child entries in the CraftCMS admin, viewed the web and the error happened sometimes.  In general, I tried some ways: eager-loading `with(['image_field'])` to fetch entries, unbuffered database connection (just found the article and enabled it in the file .env), `{% cache for 5 minutes %}` tag for loops, PHP memory limit expansion (512MB, RAM 1GB). That's it.  
> **username_0**: The error happened again with more bytes https://i.imgur.com/qXy0oTM.png  
> **username_1**: My theory is (based on the error message) that the VM is running out of memory. 1GB VM, you figure the OS and system libraries take up 400-500MB. Web server and database could take up another 200-300MB, which doesn't leave a lot left to process heavy-handed PHP and database requests (especially large ones).  
> **username_0**: I hope this error is due to out of memory only. I noted there are more bytes after creating new entries. Can you tell me if there is any problem how I'm building the web? Something wrong related to technical issues? Or lots of requests to database? Is there any better way to decrease the number of requests to database? For example, use Element API to create the entry API (get all child entries), then use Feed Me plugin to fetch and show all child entries by the parent entry. Please share your ideas how to build a better webtoon (requests, performance, etc). Thanks so much.  

---

## 0 answers

