Memory error occures

Hello!

I have a table of records where user have uploaded images (like 15-30 images) with high resolution (up to 5MB) and I want to bulk compress that images using external tinyPNG API.

I created script which selects record and then I have a loop of replacing images with compressed ones. If amount of mages is not big this script works. But for big amount of images for a record it crashes.

How can I fix the script not to overload memory?

My schema of this record is complex and it looks like system have to keep in memory everything to update whole record, i have to idea how to divide it to small chunks for memory...


This record record contains array of object, where each one contains array of images. and for 1 record there can be 30-40 images total..


7 replies