/tmp folder flooded with magick files

Apparently, when uploading (a lot of) images in Pimcore, the ImageMagick process fails every now and then, resulting in a lot of temporary magick-* and, it seems, also php* files. The magick-* files are hundreds up MBs large. On one installation they were 700 MB or larger. At some point this would cause the server to break down, as the available disk space was all used up.

Does anyone have any idea why this is happening? Or even better, how to fix it? I’ve been looking around, but haven’t been able to find a good solution, other than adding a cron job to clean up the files.


/tmp $ ls -hal
total 16G
drwxr-xr-x  6 user user  12K Nov 19 12:15 .
drwxr-xr-x 18 root root 4.0K Feb 18  2020 ..
-rw-------  1 user user 230M Nov 18 18:42 magick-17482k3gA9dYSDQcF
-rw-------  1 user user 230M Oct 20 07:34 magick-179379RlMWBhNMO8q
-rw-------  1 user user 230M Nov 18 18:42 magick-20430hlXGsjyxb3Z9
-rw-------  1 user user 230M Nov 18 18:42 magick-2736728HpmzO6f4Ev
-rw-------  1 user user 230M Nov 18 18:42 magick-27378gTXikJYuUlTY
-rw-------  1 user user 230M Nov 18 18:42 magick-27395NHu6Bz4DcazV
-rw-------  1 user user 230M Nov 18 18:42 magick-27820-DgMYQ8CARGr
-rw-------  1 user user 230M Nov 18 18:42 magick-278225SxfekmqiVau
-rw-------  1 user user 230M Oct 20 07:34 magick-27958AEe1f4nTnbDo
-rw-------  1 user user 230M Oct 20 07:34 magick-27976CBA-Lm7Bw49P
...
-rw-------  1 user user 3.7M Oct 20 07:33 php09hE3y
-rw-------  1 user user  87M Nov 18 22:50 php0CquPg
-rw-------  1 user user 4.1M Oct 20 07:33 php0Lq9gM
-rw-------  1 user user 3.6M Nov 18 18:41 php0TYbKu
-rw-------  1 user user 3.9M Oct 20 07:33 php0ob0yd
-rw-------  1 user user 4.3M Oct 20 07:33 php0s8FMG
-rw-------  1 user user 3.5M Nov 19 07:21 php1pY8kY
-rw-------  1 user user 4.1M Nov 19 10:25 php2c6hbA
-rw-------  1 user user 4.1M Nov 19 09:02 php2jzZD3
-rw-------  1 user user 4.2M Oct 20 07:33 php2s1b7R

Using the following cron jobs for automatic cleanup. The first 2 lines will clean up old files based on their age.

In one case this was still insufficient, since a user was uploading a lot of very large images within a short time, causing the /tmp folder to fill up very quickly. Therefore the last line removes images which are at a certain filesize treshold. I picked a treshold just below the usual size of the magick-* files (see list in first post).

# Temporary solution to prevent /tmp from being filled with 200+ MB ImageMagick files
0 * * * * find /tmp/ -mmin +119 -type f -name 'magick-*' -delete
0 * * * * find /tmp/ -mmin +119 -type f -name 'php*' -delete

*/5 * * * * find /tmp/ -mmin +5 -type f -name 'magick-*' -size +220M -delete