Documentation
-
Home
-
Getting Started
-
Common Tasks
-
The Servd Plugin
-
Project Settings
-
Domains & SSL
-
Importing & Cloning
-
Assets
-
Logs
-
Plans and Billing
-
Addons
-
Team & Project Management
-
Project Security
-
Your Account
-
Troubleshooting
-
Restart Instances
-
Repair Database
-
Craft isn't installed yet
-
Speeding Up Your Project
-
My Uploaded Assets Are Disappearing
-
My Sessions Are Expiring Too Soon
-
Why Are My Environments Behaving Differently?
-
No URL found for submodule path
-
Composer and Private Repositories
-
Composer out of memory errors
-
An SSL certificate for a domain has failed to generate or renew
-
Animated GIFs Displaying Incorrectly
-
Out of memory whilst running CLI tasks
-
CloudFlare: domain already exists
-
Permission Denied Whilst Generating PDFs
-
"server reached max_children setting (5), consider raising it"
-
Missing composer "allow-plugins" config
-
Unexpected robots.txt Content
-
Why is Servd is slower than my old VPS server?
-
Error: headers already sent
-
Where's the node_modules directory?
-
-
Cookbook
-
Now & Next
-
The Small Print
Out of memory whilst running CLI tasks
Many of Craft's CLI commands can suffer from memory leaks when operating over a large number of objects. One way to prevent this from occurring is to run the commands in small batches, resetting the memory usage between each batch.
Luckily Craft provides --limit and --offset parameters for many of its CLI commands. We can use these to process a small number of objects at a time.
Doing this manually could take a long time, so we like to use a little bit of bash scripting to automate the process for us:
c=0; while [[ c -lt 45000 ]]; do ./craft resave/orders --update-search-index=1 --offset=$c --limit=500; ((c = $c + 500)); done
You just need to:
- replace the 45000 with a number slightly higher than the total number of objects you expect to be included in the process
- replace the 500s with the size of each batch. This number will depend on how quickly you're hitting memory issues. Lower will reset the memory usage more often.
- replace ./craft resave/orders --update-search-index=1 with whatever command you'd like to run
Once you have your bash script ready to go you can start a Shell session from the Servd dashboard and paste it in!