How to clean /var/tmp folder which is now 8 GB in size?

Your software
My Mautic version is: 5.1.1
My PHP version is: 8.1
My Database type and version is: MariaDB 10

Your problem
My problem is:

/var/tmp folder is >8GB in storage

Is it safe to delete the contents when in maintenance mode?

Hi, the issue seems to be /tmp/var/twig folder, where it is full of PHP files with twig compiled email templates that had values interpolated.

It is up to 15GB now, majority is over 30 days old.

Is it safe to delete the files that are over 7 days old?

And is there a console command to clear this cache periodically? When I run console command “cache:clear”, it does not do anything to the /tmp/var/twig folder.

Hi @ctotech,

Let me clarify:

  • mautic:cache:clear clears the cache from var/cache.
  • mautic:maintenance:cleanup cleans up anonymous visitors, LP hits, and old audit log entries.

If most of your cache is coming from the /tmp/var/twig folder it is likely due to compiled Twig templates generated for emails. These templates are compiled dynamically when you send emails, with variables replaced by actual values (first/last names for example).

Regarding deleting them: it could be safe to delete it, however be cautious if you’re doing it automatically, especially if there are active campaigns running. I recommend waiting at least until the campaign finishes before clearing those PHP files!

Hope I helped.
Best regards,
Ricardo

Hi @ricfreire,

Thanks for the lead.

Is there a way to distinguish between which files are associated to Transactions vs. Segment emails?

So far, we have only been sending Transactional emails, but are intending to start using Campaigns soon, so the auto-delete at 7 days may be problematic.

I may need to write a PHP script for a cron task to handle the clean-up of /tmp/var/twig files, based on left-joining the column values to find the non-active Campaign twig cache files only.

Also, if I delete the /tmp/var/twig files, won’t Mautic just recreate them if still needed?

Thanks for your guidance🙏

Hello!

The twig files should not be associated with your emails. Everything regarding emails are stored in the DB in your email_stats table. The email_stats table is using the email_id found in the emails table, which also contains an email_type column. This column can tell you if an email is transactional or segment email.

Recreating your cash is independent from your var/tmp.

Joey

1 Like