Laravel 控制台中的 sendOutputTo
sendOutputTo in Laravel Console
我通过 Laravel 控制台安排了一个 cronjob。它正在工作并在每一分钟给出结果。但是我尝试使用 sendOutputTo
和 appendOutputTo
方法将输出写入文件。但这不是写入文件。我的文件有写权限。
下面是我的代码:
Kernel.php
protected function schedule(Schedule $schedule) {
$filePath = base_path() . "\cron\CleanSession.txt";
$schedule->command('cleansession')
->everyMinute()
->sendOutputTo($filePath);
}
Session.php
public function handle() {
$this->info('Display this on the screen');
$onlineCodeObj = new OnlineCode();
if ($onlineCodeObj->cleanSession()) {
echo "SESSION CLEANED : echo" . "\n";
return "SESSION CLEANED: return" . "\n";
}
echo "SESSION CLEANED : echo2" . "\n";
return "SESSION CLEANED: return2" . "\n";
}
问题已解决。更改了路径
$filePath = base_path() . "\cron\CleanSession.txt";
到 $filePath = base_path() . "/cron/CleanSession.txt";
我通过 Laravel 控制台安排了一个 cronjob。它正在工作并在每一分钟给出结果。但是我尝试使用 sendOutputTo
和 appendOutputTo
方法将输出写入文件。但这不是写入文件。我的文件有写权限。
下面是我的代码:
Kernel.php
protected function schedule(Schedule $schedule) {
$filePath = base_path() . "\cron\CleanSession.txt";
$schedule->command('cleansession')
->everyMinute()
->sendOutputTo($filePath);
}
Session.php
public function handle() {
$this->info('Display this on the screen');
$onlineCodeObj = new OnlineCode();
if ($onlineCodeObj->cleanSession()) {
echo "SESSION CLEANED : echo" . "\n";
return "SESSION CLEANED: return" . "\n";
}
echo "SESSION CLEANED : echo2" . "\n";
return "SESSION CLEANED: return2" . "\n";
}
问题已解决。更改了路径
$filePath = base_path() . "\cron\CleanSession.txt";
到 $filePath = base_path() . "/cron/CleanSession.txt";