bnzo/livewire-tmp-cleanup
Schedules automatic cleanup of Livewire temporary uploads on S3-compatible disks. Adds the livewire-tmp:clean Artisan command to delete files older than a configurable age, with optional dry-run. Auto-scheduled daily, safe for multi-server deployments.
livewire:model) persist indefinitely on S3-compatible storage due to lack of native lifecycle management. Ideal for serverless/cloud environments (e.g., Laravel Cloud, Forge) where S3 lifecycle rules are unavailable.schedule:run) for execution.TmpCleanupExecuted) for audit logging or triggering downstream actions (e.g., analytics).APP_SCHEDULER_ENABLED=true).Artisan::call()) and mock S3 disks (e.g., MockFlysystemAdapter).LastModified precision).withoutOverlapping()).temporary_file_upload disk/directory structure (monitor Livewire releases).onOneServer() ensures single-server execution, but no distributed lock mechanism for multi-server setups (e.g., Laravel Horizon).x-amz-* headers)?is_processed=true metadata)?tmp_upload disk changes)?php artisan storage:link + S3 disk config.temporary_file_upload disk/directory in config/filesystems.php.composer require bnzo/livewire-tmp-cleanup
php artisan vendor:publish --provider="Bnzo\LivewireTmpCleanup\LivewireTmpCleanupServiceProvider"
cleanup_age (default: 24 hours) and disk/directory.php artisan livewire-tmp:clean --dry-run..env: APP_SCHEDULER_ENABLED=true.app/Console/Kernel.php (already auto-registered):
$schedule->command('livewire-tmp:clean')->daily()->onOneServer()->withoutOverlapping();
php artisan schedule:run manually for initial cleanup.temporary_file_upload disk. Custom Livewire setups may need config overrides.cleanup_age in production (e.g., start with 48 hours)..env or published config (no code changes).storage/logs/laravel.log).s3:DeleteObject permissions.temporary_file_upload disk matches Livewire’s config.cleanup_age if needed.onOneServer() prevents duplicate runs in multi-server setups.ListObjectsV2 with MaxKeys for pagination.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| S3 API throttling | Cleanup pauses or fails | Use withoutOverlapping() + exponential backoff. |
| Permission denied (S3/IAM) | No files deleted | Audit IAM roles; test with dry-run first. |
| Livewire disk config changed | Cleanup targets wrong directory | Monitor Livewire updates; validate config. |
| Server outage during cleanup | Partial cleanup | Idempotent design; retry on next schedule. |
| Large directory (>1M files) | Timeout/memory exhaustion | Implement chunking or queue-based processing. |
| S3 provider outage | Cleanup skipped | Alerting on scheduler failures. |
How can I help you explore Laravel packages today?