misterpaladin/cleaner

Laravel的垃圾清理包

1.0.9 2017-08-29 09:32 UTC

This package is auto-updated.

Last update: 2024-09-13 11:50:49 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

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
    },
],

执行

Cleaner每分钟运行一次(如果你设置了:[https://laravel.net.cn/docs/5.4/scheduling#introduction](https://laravel.net.cn/docs/5.4/scheduling#introduction))

手动运行: php artisan cleaner:run