You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In short, we have a long running Laravel project with lots of media (60k+ rows and counting). These media undergo conversions via de Media Library package from Spatie. All media is stored in S3. We use the provided clean command to clean up deprecated conversions. To do this, the underlying code retrieves the stored paths, which ends up calling the files method in the FilesystemAdapter provided by Laravel. The code is probably not unknown:
listContents returns a DirectoryListing instance which is then modified and then simply returns an array of string paths. Every time toArray is called (and basically the iterator contents are converted into an array), the memory usage increases. This increase isn't insane (like 2000 bytes per iteration), however you can imagine with such amounts of data this can quickly become a large amount of memory.
As you can expect, eventually the command runs out of memory.
I've tried to see what I can do to fix it, however I am unable to identify the issue of why the toArray call will simply not let go of memory, so I am not able to say if this is truly related to Flysystem or perhaps a native PHP issue. For now I've had to implement a work-around is to chunk the process, which basically means that the memory is freed and then a new process is started to continue where it had left off. It is however not an ideal solution. Any help would be appreciated.
Bug Report
Summary
In short, we have a long running Laravel project with lots of media (60k+ rows and counting). These media undergo conversions via de Media Library package from Spatie. All media is stored in S3. We use the provided clean command to clean up deprecated conversions. To do this, the underlying code retrieves the stored paths, which ends up calling the
files
method in theFilesystemAdapter
provided by Laravel. The code is probably not unknown:listContents
returns aDirectoryListing
instance which is then modified and then simply returns an array of string paths. Every timetoArray
is called (and basically the iterator contents are converted into an array), the memory usage increases. This increase isn't insane (like 2000 bytes per iteration), however you can imagine with such amounts of data this can quickly become a large amount of memory.As you can expect, eventually the command runs out of memory.
I've tried to see what I can do to fix it, however I am unable to identify the issue of why the
toArray
call will simply not let go of memory, so I am not able to say if this is truly related to Flysystem or perhaps a native PHP issue. For now I've had to implement a work-around is to chunk the process, which basically means that the memory is freed and then a new process is started to continue where it had left off. It is however not an ideal solution. Any help would be appreciated.How to reproduce
(Laravel based snippet)
Outputs:
17822728
19260872
19915000
The text was updated successfully, but these errors were encountered: