milax / cleaner
1.0.9
2017-08-29 09:32 UTC
README
Laravel的垃圾清理包
使用方法
安装包
$ composer require misterpaladin/cleaner
发布配置文件到您的项目
$ php artisan vendor:publish --tag=cleaner
将MisterPaladin\Cleaner\CleanerServiceProvider添加到您的config/app.php提供者数组
配置
/config/cleaner.php文件内容
return [ // Delete file after 3 days and 12 hours [ 'path' => 'path/to/file.ext', 'expires' => [ 'days' => 3, 'hours' => 12, ], ], // Delete directory after 30 minutes [ 'path' => 'path/to/directory', 'expires' => [ 'minutes' => 10, ], ], // Delete directory contents after 1 week [ 'path' => 'path/to/directory/*', 'expires' => [ 'weeks' => 1, ], ] // Define a path array [ 'path' => [ 'path/to/file.ext', 'path/to/directory', 'path/to/directory/*', ], 'expires' => [ 'weeks' => 1, ], ] ];
expires选项可以接受
- 秒
- 分钟
- 小时
- 天
- 周
- 月
- 年
回调
[
'path' => 'path/to/file.ext',
'expires' => [
'days' => 3,
'hours' => 12,
],
'before' => function ($path) {
// Execute before deleting the file
},
'after' => function ($path) {
// Execute after deleting the file
},
],
执行
清理器每分钟运行一次(如果设置了:https://laravel.net.cn/docs/5.4/scheduling#introduction)
手动运行:php artisan cleaner:run