0
我有一些与调度程序一起运行的命令,其中一些命令无法按预期工作,如果放在外部文件中,代码工作正常。但是当作为带有调度程序的命令运行时,它不会执行任何操作,也不会删除文件&文件没有输出。Laravel 5.1 - 命令未按预期运行
命令:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use DirectoryIterator;
class CleanExports extends Command {
protected $name = 'clean:exports';
public function fire() {
$folderName = 'exports';
if (file_exists($folderName)) {
$i = 0;
foreach (new DirectoryIterator($folderName) as $fileInfo) {
if ($fileInfo->isDot()) {
continue;
}
if (time() - $fileInfo->getCTime() >= 1*24*60*60) {
unlink($fileInfo->getRealPath());
}
$i++;
}
echo $i.' files cleaned';
}
}
}
Kernel.php
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel {
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
\App\Console\Commands\Inspire::class,
'\App\Console\Commands\CleanExports',
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule) {
$schedule->command('inspire')
->hourly();
$schedule->command('clean:exports')->everyMinute()->sendOutputTo('temp/errors.txt');
}
究竟什么不行?它不删除文件吗?更加详细一些。 – Andrew
你在工作中使用了什么样的“调度程序”? –
和'kernel.php'' \ App \ Console \ Commands \ CleanExports :: class'中的这一行代替这个''\ App \ Console \ Commands \ CleanExports'' –