laravel - Laravel 5,Mail:: with later() 不工作
问题描述
Mail
withlater()
不适用于我将其作为参数提供的时间。
$when = $final_new_days_count;//Carbon::now()->addMinutes(5);
Mail::to($user)
->later($when, new Expired($user, $when));
I'm receiving the email just when I execute the code that calls `Mail::`
With `dd($when);` I get:
Carbon {#766 ▼
+"date": "2019-07-22 23:59:59.229078"
+"timezone_type": 3
+"timezone": "UTC"
}
Actually, in the email view I'm sending this:
<p>Now: {{ \Carbon\Carbon::now() }}</p>
<p>When: {{ $when->date }}</p>
我在收到的电子邮件中看到:
Now: 2019-07-19 16:18:23
When: 2019-07-22 23:59:59.315271
那么为什么不工作later
呢?
编辑:在我的 .env 中,我有:
QUEUE_DRIVER=sync
我不能改变它,其他一些功能需要它。
编辑 2:好吧,我用 QUEUE_DRIVER=database 进行了测试,但不知道 php artisan queue:work 必须一直运行。我不能一直运行这个:S
解决方案
Laravel 邮件later
功能需要一个队列才能运行。默认情况下,您QUEUE_DRIVER
设置为sync
. 这意味着它将立即触发它。
使用redis
ordatabase
队列,以便它可以将作业排队以备后用。
QUEUE_DRIVER=redis
如果您不想一直php artisan queue:work
在命令行中运行,我建议您使用像 Supervisor 这样的流程管理器。
关于队列进程和进程管理器的文档:
https://laravel.com/docs/5.8/queues#running-the-queue-worker
安装主管:
https://cloudwafer.com/blog/how-to-install-and-configure-supervisor-on-ubuntu-16-04/
这将允许php artisan queue:work
作为后台进程运行。
如果您决定使用主管,以下配置将起作用:
`[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /path/to/artisan queue:work
autostart=true
autorestart=true
numprocs=8
redirect_stderr=true
stdout_logfile=/home/forge/app.com/worker.log`
推荐阅读
- python - 无法通过 Python 使用 selenium 按类名定位元素。为什么这样?
- vue.js - 如何设置页面格式vue js html-to-paper
- pandas - 在 lambda 函数中使用 pandas 数据框更新 dynamodb 表
- python - 我怎样才能使这个脚本更有效率?(Python)
- sql - 验证 varchar 是否遵循特定模式
- python - 在字典中按连续日期和不连续日期分组
- javascript - 仅当填写表单的所有必填字段时如何更改提交表单按钮的值(JS)
- windows - 用于查找带有时间戳的文件的 Windows 批处理脚本
- google-sheets-api - 如何获得无限的 Google Sheets API 读/写?
- javascript - 使用 canvas2pdf 库从 Canvas 导出 PDF