为什么laravel任务不使用cron运行?
我需要从laravel tasks发送电子邮件。我有这个任务的代码为什么laravel任务不使用cron运行?,laravel,cron,task,laravel-7,Laravel,Cron,Task,Laravel 7,我需要从laravel tasks发送电子邮件。我有这个任务的代码 $schedule->call(function () { $date = now()->addDays(1); echo 'step 1'; $appointment = Cita::whereDate('date', $date)->with(['patient'])->orderBy('date')->orderBy('hour')->get(); echo 'step
$schedule->call(function () {
$date = now()->addDays(1);
echo 'step 1';
$appointment = Cita::whereDate('date', $date)->with(['patient'])->orderBy('date')->orderBy('hour')->get();
echo 'step 2';
foreach($appointment as $appt) {
$data = array("name" => $appt->patient->name, "body" => 'Remember me');
if ($appt->patient->email !== null) {
Mail::to($cita->paciente->email)->send(new Reminder($data));
}
echo 'step 3';
}
})->everyMinute();
运行命令时
php artisan schedule: run
在终端中手动操作,一切正常运行,我收到电子邮件。使用邮件陷阱
然后我加上这个
* * * * * cd / app && php artisan schedule: run >> /app/log.log 2> & 1
在crontab中
我将命令输出发送到log.log文件,以便能够查看echo
只需绘制第一个回波步骤1,其余回波将不再添加到日志中
这是日志中显示的结果
Running scheduled command: Closure
step 1
不会显示任何错误,也不会向我发送电子邮件。
我使用的laravel版本是7.15.0
我希望有人能帮助我。谢谢。存储器/logs/laravel.log中有任何内容吗?这是我看到的错误。local.ERROR:找不到驱动程序SQL:从'patient'中选择*其中date'date`=2020-09-24 order by'date'asc,'hour'asc{异常:[object]Illumb\\Database\\QueryExceptioncode:0:找不到驱动程序SQL:从'citas'中选择*,其中date'date`=2020-09-24 order by'date'asc,'hour'asc at/app/vendor/laravel/framework/src/Illumb/Database/Connection.php:671[stacktrace]你确定你从cron上运行的是正确版本的php吗?我不知道问题出在哪里。但通过运行sudo apt get install php7.3-pdo php7.3-mysql命令,问题得到了解决。问题得到了解决,但我想知道为什么只有cron命令才会出现错误,在其他情况下,一切都会正常进行ll.谢谢你的帮助。这可能是因为你有两个版本的PHP:一个有pdo mysql,另一个没有。一个有pdo mysql,可以安装到/usr/local/bin,另一个没有安装到/usr/bin。你运行PHP artisan的用户…可以在$PATH中有/usr/local/bin,因此它运行第一个PHP,cron可以在另一个用户,在$PATH中没有/usr/local/bin,因此它从/usr/bin/运行另一个PHP。当您以后安装pdo和mysql扩展时,它们是为/usr/bin版本安装的,因此它现在可以工作了。