craft3-beam icon indicating copy to clipboard operation
craft3-beam copied to clipboard

Add automatic cleanup of temporary files after download

Open Copilot opened this issue 1 month ago • 0 comments

Beam creates temporary files during CSV/XLSX generation but never deletes them, accumulating disk space over time (15GB reported).

Changes

  • Automatic cleanup: DefaultController::actionIndex() now registers a shutdown function to delete temp files after the response is sent. Uses register_shutdown_function() to ensure deletion occurs after sendFile() completes streaming.

  • Error handling: Logs cleanup failures via Craft::warning() instead of suppressing errors.

  • Documentation: Added "Temporary File Management" section to README with manual cleanup commands and cron job example for edge cases.

// Register shutdown function to clean up after response
register_shutdown_function(function() use ($path) {
    if (file_exists($path)) {
        if (!unlink($path)) {
            Craft::warning("Failed to delete temporary file: {$path}", __METHOD__);
        }
    }
});

return Craft::$app->getResponse()->sendFile($path, $filename, [
    'mimeType' => $config['mimeType'],
]);

[!WARNING]

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • asset-packagist.org
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/h1ctrO /usr/bin/composer install (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Temp files never cleared?</issue_title> <issue_description>I've been running Beam on a client site for well over a year now, and recently started encountering issues with disk space on the server. After investigating I found 15GB of files in Beam's temp directory!

Does Beam never clear out its temp files created during CSV creation? Or is it assumed that Craft will do this on a regular basis?</issue_description>

<agent_instructions>Come up with some suggestions for how to solve this. Regardless of outcome, lets update readme to point this out.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@sjelfull Beam does not do anything to clean up temp files, no. It assumes Craft/you do it on e regular basis.
  • Fixes sjelfull/craft3-beam#19

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot avatar Jan 06 '26 09:01 Copilot