6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WEBページでArtisanコマンドを実行する

Posted at

Artisanコマンドで作成したバッチをコントローラ等で実行したい。
Queueという手段もありますが、そこまで設定する必要がない場合。

exec('php "'.base_path('artisan').'" command:test --env=production > /dev/null &');

--env=productionは参照しているDB等を設定している。
コマンドから実行する場合はWEBサーバーを通さないのでconfigのenv設定が使用されてしまう。

use Artisan;

Artisan::call('command:test', $argument_map_list);

はバックグラウンド実行にならないのでタイムアウトの可能性

参考

Artisanコマンドへ--env=testingオプションを指定した場合に、.envファイルをオーバーライドします。
プログラムによるコマンド実行

6
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?