- How do I install and set up this package in Laravel?
- Run `composer require bnzo/livewire-tmp-cleanup` and ensure your Laravel scheduler is enabled (`APP_SCHEDULER_ENABLED=true`). The package auto-schedules a daily cleanup at midnight using Livewire’s default `temporary_file_upload` disk. No additional config is needed unless you customize the disk or directory.
- Does this work with Cloudflare R2 or only AWS S3?
- Yes, it works with any S3-compatible storage, including Cloudflare R2, AWS S3, MinIO, and DigitalOcean Spaces. The package uses Laravel’s Flysystem adapter, so it leverages your existing disk configuration. R2 may require minor adjustments for metadata handling, but the core functionality remains the same.
- Can I change the cleanup frequency or run it manually?
- By default, it runs daily. To customize, set `LIVEWIRE_TMP_CLEANUP_SCHEDULE=false` in `.env` and manually register it in `routes/console.php` with a frequency like `hourly()` or `weekly()`. You can also trigger it manually with `php artisan livewire-tmp:clean` for immediate dry-run or cleanup.
- What happens if I have 100,000+ temporary files? Will it time out?
- The package processes files in batches to avoid timeouts. For very large directories (e.g., 1M+ files), consider increasing PHP’s `max_execution_time` or splitting cleanup into smaller chunks by adjusting the scheduler frequency. The `withoutOverlapping(60)` setting prevents overlapping runs, reducing strain.
- How do I test this package in my Laravel app?
- Use the dry-run mode with `php artisan livewire-tmp:clean --dry-run` to preview deletions without modifying files. For automated testing, mock the S3 disk using Laravel’s `MockFlysystemAdapter` and assert the command’s output. Unit tests can verify the cleanup logic with `Artisan::call()` in PHPUnit.
- Will this break if Livewire changes its temp upload disk path?
- The package defaults to Livewire’s `temporary_file_upload` disk, but you can override it via config. Monitor Livewire releases for disk path changes and update the `disk` or `directory` settings in the package config if needed. The package is designed to be flexible for such adjustments.
- Can I exclude certain files from cleanup (e.g., processed uploads)?
- Currently, the package deletes files based solely on age. To whitelist files, you’d need to extend the package or modify the cleanup logic to check for metadata (e.g., `is_processed=true`). Consider adding a custom filter via the package’s `getFilesToClean()` method if you need this feature.
- Does this work in Laravel Cloud or multi-server setups?
- Yes, the package includes `onOneServer()` and `withoutOverlapping(60)` to ensure only one server runs the cleanup at a time, preventing conflicts. For distributed setups (e.g., Laravel Horizon), you may need a distributed lock mechanism, but the current design is safe for most multi-replica deployments.
- Are there any known issues with specific S3 providers like Backblaze B2?
- The package should work with most S3-compatible providers, but some edge cases may arise. For example, Backblaze B2 or DigitalOcean Spaces might require adjustments for custom metadata or API quirks. Test thoroughly in staging, and check the package’s GitHub issues for provider-specific reports.
- How can I monitor or log cleanup activity for debugging?
- The package logs deletions and errors to Laravel’s default log channel. For structured monitoring, extend the command to emit events (e.g., `TmpCleanupExecuted`) or integrate with tools like Sentry or Laravel Horizon. Metrics for deleted files/bytes can be added via custom logging or a Prometheus client.