- 오래걸리는 작업 처리용(메일 전송, 파일 변환등)
https://laravel.kr/docs/6.x/queues
* 큐 설정
.env 파일
QUEUE_DRIVER=redis
- sync 동기
- redis 비동기
* config/queue.php 파일
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => '{default}',
'retry_after' => 90,
],
* 큐 작업 생성(Job 생성)
php artisan make:job job1
App\Jobs\job1.php 파일 생성됨
* 큐 작업 실행
job1::dispatch($option)->onConnection('redis')->onQueue('high');//비동기
job1::dispatch($option);//동기설정시, 기본 설정 이용
* 큐 워커 실행
php artisan queue:work --queue=high,default
- 소스 코드가 수정되면 재시작해야 변경된 코드가 적용
php artisan queue:restart
//--------------------------------
< Horizon 이용 >
Redis Queue 작업 처리, 모니터링, 현황 표시
* 설치
composer require laravel/horizon
php artisan horizon:install
php artisan queue:failed-table
php artisan migrate
//-----------------------------------
* 설정 : config/horizon.php
'environments' => [
'production' => [
'email' => [
'connection' => 'redis',
'queue' => ['default', 'email', 'file'],
'balance' => 'simple',
'processes' => 10,
'sleep' => 3, // 작업이 없으면 쉬기, 초
'timeout' => 300, //최대 수행시간, 초단위
'retry_after' => 310, //재시도할 시간, timeout값보다 커야 한다.
'tries' => 3, // 쵀대 재시도 횟수
'delay' => 1, // 재시도 할때 쉬는 시간, 기본=0
],
* 실행
php artisan horizon
- 종료
php artisan horizon:terminate
//------------------------------
* Supervisor 로 구동하기
- horizon 프로세스가 종료되면 자동 시작
- 설정
/etc/supervisor/conf.d/horizon.d 파일 생성
[program:horizon]
process_name=%(program_name)s
command=php /home/forge/app.com/artisan horizon
autostart=true
autorestart=true
user=forge
redirect_stderr=true
stdout_logfile=/home/forge/app.com/horizon.log
stdout_logfile_maxbytes=100MB
stdout_logfile_backups=10
stderr_logfile=/home/forge/app.com/horizon-err.log
stderr_logfile_maxbytes=100MB
stderr_logfile_backups=10
service supervisor restart
supervisorctl reload
supervisorctl reread
supervisorctl update
supervisorctl start horizon
reread - Reread supervisor configuration. Do not update or restart the running services.
update - Restart service(s) whose configuration has changed. Usually run after 'reread'.
reload - Reread supervisor configuration, reload supervisord and supervisorctl, restart services that were started.
restart - Restart service(s)
https://www.onurguzel.com/supervisord-restarting-and-reloading/
//------------------------------
horizon + supervisor 로 구동 중인데 소스가 변경된경우 적용하는 방법
- 방법1 : 권장 - supervisor로 horizon을 재시작
sudo supervisorctl restart horizon
- 방법2 : horizon 종료
- horizon을 종료 하면 supervisor가 자동으로 재시작한다.
php artisan horizon:terminate
'Code > PHP' 카테고리의 다른 글
[PHP] underscore(lodash) 같은 라이브러리 (0) | 2020.04.05 |
---|---|
[php] PCNTL ( Process Control) 확장 사용법 예제 (0) | 2020.03.25 |
[라라벨] 큐 사용법(Queue, Job, Horizon) (0) | 2020.03.24 |
php 7.3 PCNTL 확장 기능 활성화 방법 (0) | 2020.03.24 |
[php] 서버에서 텔레그램 메시지 전송 (0) | 2020.03.19 |
[php] PHP 7.4의 새로운 기능 (0) | 2020.03.12 |
댓글을 달아 주세요