PHP

PHP


workerman定时

<h1>引入扩展</h1> <p><code>composer require workerman/workerman</code> <code>composer require workerman/crontab</code></p> <h1>生成命令文件</h1> <p><code>php artisan make:command crontab</code></p> <h1>修改代码</h1> <pre><code>&amp;lt;?php namespace App\Console\Commands; use Illuminate\Console\Command; use Illuminate\Support\Facades\Artisan; use Workerman\Worker; class Crontab extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'crontab'; /** * The console command description. * * @var string */ protected $description = 'crontab'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * */ public function handle() { $worker = new Worker(); $worker-&amp;gt;onWorkerStart = [$this, 'onWorkerStart']; $worker-&amp;gt;runAll(); } public function onWorkerStart() { // 每秒执行 new \Workerman\Crontab\Crontab('* * * * * *', function(){ Artisan::call('需要执行的任务'); }); } }</code></pre> <h1>执行任务</h1> <p><code>php artisan crontab</code></p> <h1>守护进程</h1> <p>pm2执行crontab.yml</p> <pre><code>apps: - name: crontab script: artisan exec_mode: fork interpreter: php instances: 1 args: - crontab restart_delay: 3000 pid_file: ./storage/app/crontab.pid</code></pre>

页面列表

ITEM_HTML