데몬 감독자를 사용하여 Laravel 프레임워크를 기반으로 예약된 작업(밀리초) 구현
이 기사의 내용은 Laravel 프레임워크를 기반으로 예정된 작업(밀리초)을 구현하기 위해 데몬 슈퍼바이저를 사용하는 것에 대한 내용입니다. 필요한 친구들이 참고할 수 있기를 바랍니다.
회사에서는 X분 내에 Y초마다 인터페이스 순환 교육을 구현해야 합니다. Linux
와 함께 제공되는 crontab
은 정확할 수 있지만 몇 분 정도밖에 안되는 것 같습니다. 초 단위로 정확해야 하며 수요를 충족하지 못합니다. Linux
自带的crontab
貌似只精确到分钟,虽然可以到精确到秒,但是并不满足需求。
选型
公司项目都是 基于 Laravel
框架,所以这个没得选。守护进程用的 supervisor
Laravel
프레임워크를 기반으로 하므로 선택의 여지가 없습니다. 데몬 프로세스는 supervisor
를 사용하는데, 이 사람이 우리의 요구를 충족시킬 수 있는지 봅시다codeprocess Guardiannamespace App\Console\Commands; use Illuminate\Console\Command; use Cache; use Carbon\Carbon; class TaskCommand extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'ue:task {--id= : 当前编号} {--max= : 最大线程} {--sleep= : 休眠多少毫秒} {--debug= : 是否调试模式} '; /** * The console command description. * * @var string */ protected $description = 'Command description'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return mixed */ public function handle() { $this->id = $this->option('id') ?? '00'; $this->max = $this->option('max') ?? 32; $this->sleep = $this->option('sleep') ?? 700; $this->debug = $this->option('debug') ?? false; if ($this->id > $this->max) { return true; } while (true) { $this->doRun(); } } /** * * @param int $taskId * @return boolean */ protected function doRun() { $lock = sprintf('task:%03d:%s', $this->id, time()); $data = [ 'id' => $this->id, 'max' => $this->max, 'time' => (new Carbon)->format('Y-m-d H:i:s.u'), 'key' => $lock, ]; try { $result = cache()->get($lock); if ($result) { $data['message'] = 'Task Has been executed.'; $this->wait($this->sleep); return true; } cache()->put($lock, true, 2); $data['message'] = 'Task Executed.'; $this->logger($data); $this->wait($this->sleep); } catch (\Exception $ex) { $data['message'] = $ex->getMessage(); cache()->put($data, true, 2); $this->wait($this->sleep); } } /** * 毫秒 * @param string $time */ protected function wait($time) { $wait = $time * 1000; usleep($wait); } protected function logger($message) { if($this->debug){ $time = (new Carbon)->format('Y-m-d H:i:s.u'); $this->line(array_get($message, 'message') .' - '. $time); } logger()->stack(['task'])->debug(null, $message); } }로그인 후 복사
[program:task-worker]
process_name=%(program_name)s_%(process_num)02d
command=/usr/bin/php /home/wwwroot/demo/artisan ue:task --id=%(process_num)02d --max=8
autostart=true
autorestart=true
user=www
numprocs=8
redirect_stderr=true
stdout_logfile=/home/wwwroot/demo/storage/logs/worker.log
로그인 후 복사
위는 Supervisorrendering
[program:task-worker] process_name=%(program_name)s_%(process_num)02d command=/usr/bin/php /home/wwwroot/demo/artisan ue:task --id=%(process_num)02d --max=8 autostart=true autorestart=true user=www numprocs=8 redirect_stderr=true stdout_logfile=/home/wwwroot/demo/storage/logs/worker.log
Task Executed. - 2018-08-14 22:17:18.985094 Task Executed. - 2018-08-14 22:17:19.336115 Task Executed. - 2018-08-14 22:17:20.038236 Task Executed. - 2018-08-14 22:17:21.090470 Task Executed. - 2018-08-14 22:17:22.142716 Task Executed. - 2018-08-14 22:17:23.195126 Task Executed. - 2018-08-14 22:17:24.247698 Task Executed. - 2018-08-14 22:17:25.300066 Task Executed. - 2018-08-14 22:17:26.352638 Task Executed. - 2018-08-14 22:17:27.054124 Task Executed. - 2018-08-14 22:17:28.106420 Task Executed. - 2018-08-14 22:17:29.158906 Task Executed. - 2018-08-14 22:17:30.211438 Task Executed. - 2018-08-14 22:17:31.263542 Task Executed. - 2018-08-14 22:17:32.315923 Task Executed. - 2018-08-14 22:17:33.017096 Task Executed. - 2018-08-14 22:17:34.068963 Task Executed. - 2018-08-14 22:17:35.121267 Task Executed. - 2018-08-14 22:17:36.173600 Task Executed. - 2018-08-14 22:17:37.226165
의 구성입니다.
[2018-08-14 22:12:24] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:24.389224","key":"task:001:1534255944","message":"Task Executed."} [2018-08-14 22:12:25] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:25.390158","key":"task:001:1534255945","message":"Task Executed."} [2018-08-14 22:12:26] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:26.391594","key":"task:001:1534255946","message":"Task Executed."} [2018-08-14 22:12:27] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:27.393196","key":"task:001:1534255947","message":"Task Executed."} [2018-08-14 22:12:28] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:28.395124","key":"task:001:1534255948","message":"Task Executed."} [2018-08-14 22:12:29] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:29.396796","key":"task:001:1534255949","message":"Task Executed."} [2018-08-14 22:12:30] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:30.398666","key":"task:001:1534255950","message":"Task Executed."} [2018-08-14 22:12:31] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:31.400561","key":"task:001:1534255951","message":"Task Executed."} [2018-08-14 22:12:32] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:32.402462","key":"task:001:1534255952","message":"Task Executed."} [2018-08-14 22:12:33] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:33.404092","key":"task:001:1534255953","message":"Task Executed."} [2018-08-14 22:12:34] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:34.405550","key":"task:001:1534255954","message":"Task Executed."} [2018-08-14 22:12:35] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:35.407197","key":"task:001:1534255955","message":"Task Executed."} [2018-08-14 22:12:36] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:36.408920","key":"task:001:1534255956","message":"Task Executed."} [2018-08-14 22:12:37] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:37.410841","key":"task:001:1534255957","message":"Task Executed."} [2018-08-14 22:12:38] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:38.412764","key":"task:001:1534255958","message":"Task Executed."} [2018-08-14 22:12:39] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:39.414518","key":"task:001:1534255959","message":"Task Executed."} [2018-08-14 22:12:40] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:40.416229","key":"task:001:1534255960","message":"Task Executed."} [2018-08-14 22:12:41] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:41.418001","key":"task:001:1534255961","message":"Task Executed."} [2018-08-14 22:12:42] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:42.419476","key":"task:001:1534255962","message":"Task Executed."} [2018-08-14 22:12:43] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:43.421388","key":"task:001:1534255963","message":"Task Executed."} [2018-08-14 22:12:44] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:44.423164","key":"task:001:1534255964","message":"Task Executed."} [2018-08-14 22:12:45] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:45.424798","key":"task:001:1534255965","message":"Task Executed."} [2018-08-14 22:12:46] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:46.426667","key":"task:001:1534255966","message":"Task Executed."} [2018-08-14 22:12:47] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:47.428553","key":"task:001:1534255967","message":"Task Executed."} [2018-08-14 22:12:48] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:48.430427","key":"task:001:1534255968","message":"Task Executed."} [2018-08-14 22:12:49] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:49.432118","key":"task:001:1534255969","message":"Task Executed."} [2018-08-14 22:12:50] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:50.433893","key":"task:001:1534255970","message":"Task Executed."} [2018-08-14 22:12:51] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:51.435711","key":"task:001:1534255971","message":"Task Executed."} [2018-08-14 22:12:52] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:52.437015","key":"task:001:1534255972","message":"Task Executed."} [2018-08-14 22:12:53] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:53.438352","key":"task:001:1534255973","message":"Task Executed."} [2018-08-14 22:12:54] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:54.439989","key":"task:001:1534255974","message":"Task Executed."} [2018-08-14 22:12:55] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:55.441580","key":"task:001:1534255975","message":"Task Executed."} [2018-08-14 22:12:56] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:56.443116","key":"task:001:1534255976","message":"Task Executed."} [2018-08-14 22:12:57] local.DEBUG: {"id":"1","max":"32","time":"2018-08-14 22:12:57.445006","key":"task:001:1534255977","message":"Task Executed."}
PHP를 사용하여 데몬 작업 백그라운드 실행 및 멀티스레딩 구현(php-resque 사용 지침) php 예약 작업 프레임워크 공유PHP 프레임워크에서 비동기 프로세스를 실행하는 감독자 구현 라라벨🎜🎜 🎜
위 내용은 데몬 감독자를 사용하여 Laravel 프레임워크를 기반으로 예약된 작업(밀리초) 구현의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











PHP는 주로 절차 적 프로그래밍이지만 객체 지향 프로그래밍 (OOP)도 지원합니다. Python은 OOP, 기능 및 절차 프로그래밍을 포함한 다양한 패러다임을 지원합니다. PHP는 웹 개발에 적합하며 Python은 데이터 분석 및 기계 학습과 같은 다양한 응용 프로그램에 적합합니다.

PHP는 웹 개발 및 빠른 프로토 타이핑에 적합하며 Python은 데이터 과학 및 기계 학습에 적합합니다. 1.PHP는 간단한 구문과 함께 동적 웹 개발에 사용되며 빠른 개발에 적합합니다. 2. Python은 간결한 구문을 가지고 있으며 여러 분야에 적합하며 강력한 라이브러리 생태계가 있습니다.

Laravel은 웹 응용 프로그램을 쉽게 구축하기위한 PHP 프레임 워크입니다. 설치 : Composer를 사용하여 전 세계적으로 Laravel CLI를 설치하고 프로젝트 디렉토리에서 응용 프로그램을 작성하는 등 다양한 기능을 제공합니다. 라우팅 : Routes/Web.php에서 URL과 핸들러 간의 관계를 정의하십시오. 보기 : 리소스/뷰에서보기를 작성하여 응용 프로그램의 인터페이스를 렌더링합니다. 데이터베이스 통합 : MySQL과 같은 데이터베이스와 상자 외 통합을 제공하고 마이그레이션을 사용하여 테이블을 작성하고 수정합니다. 모델 및 컨트롤러 : 모델은 데이터베이스 엔티티를 나타내고 컨트롤러는 HTTP 요청을 처리합니다.

PHP는 1994 년에 시작되었으며 Rasmuslerdorf에 의해 개발되었습니다. 원래 웹 사이트 방문자를 추적하는 데 사용되었으며 점차 서버 측 스크립팅 언어로 진화했으며 웹 개발에 널리 사용되었습니다. Python은 1980 년대 후반 Guidovan Rossum에 의해 개발되었으며 1991 년에 처음 출시되었습니다. 코드 가독성과 단순성을 강조하며 과학 컴퓨팅, 데이터 분석 및 기타 분야에 적합합니다.

phphassignificallyimpactedwebdevelopmentandextendsbeyondit

CRAFTCMS를 사용하여 웹 사이트를 개발할 때 특히 CSS 및 JavaScript 파일을 자주 업데이트 할 때 자주 리소스 파일 캐싱 문제가 발생하면 이전 버전의 파일이 여전히 브라우저에서 캐싱 될 수 있으므로 사용자는 최신 변경 사항을 볼 수 없습니다. 이 문제는 사용자 경험에 영향을 줄뿐만 아니라 개발 및 디버깅의 어려움을 증가시킵니다. 최근에 나는 프로젝트에서 비슷한 문제를 겪었고, 약간의 탐색 후 플러그인 Wiejeben/Craft-Laravel-Mix를 발견하여 캐싱 문제를 완벽하게 해결했습니다.

Laravel provides a comprehensive Auth framework for implementing user login functions, including: Defining user models (Eloquent model), creating login forms (Blade template engine), writing login controllers (inheriting Auth\LoginController), verifying login requests (Auth::attempt) Redirecting after login is successful (redirect) considering security factors: hash passwords, anti-CSRF protection, rate limiting and security 헤더. 또한 Auth Framework는 비밀번호 재설정, 이메일 등록 및 확인과 같은 기능도 제공합니다. 자세한 내용은 Laravel 문서를 참조하십시오 : https://laravel.com/doc

Laravel 프레임 워크를 배우고 싶지만 자원이나 경제적 압력이 없습니까? 이 기사는 Laravel의 무료 학습을 제공하며 온라인 플랫폼, 문서 및 커뮤니티 포럼과 같은 리소스를 사용하여 PHP 개발 여정을 시작하는 것에서 마스터까지의 탄탄한 토대를 마련하는 방법을 가르쳐줍니다.
