本文实例讲述了Laravel框架定时任务2种实现方式。分享给大家供大家参考,具体如下:
第一种
1、生成一个commands文件
> php artisan make:command test
2、打开文件进行修改
laravel\App\Console\Commands\test.php
<"php artisan test:insert " 指令 /** * The console command description. * * @var string */ protected $description = 'insert Test table some test data'; // 对上面指令的描述 /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return mixed */ public function handle() { // 编写你要的定时任务执行的代码! # eg Log::info('test'); } }
> php artisan list
查看
3、然后修改: laravel\app\Console\Kernel.php 文件
<"color: #0000ff">laravel\storage\logs\laravel.log第二种
使用 shell脚本执行
因为
php artisan list
可以查看到 执行指令test:insert
所以可以考虑用 .sh 脚本执行,还是类似上面
crontab -e
编写1、先编写 .sh 脚本 laravel/test.sh 放在项目某个位置,文件内写入
php artisan test:insert上面指令在命令行手动每执行一次就可以触发一次编写的程序,相当于给 laravel.log 写入一次 test
2、使用
crontab -e
编写 执行 第一步写的 test.sh 脚本* * * * * laravel/test.sh
以上两种均可看到 laravel.log 日志
更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。
风云阁资源网 Design By www.bgabc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
风云阁资源网 Design By www.bgabc.com
暂无评论...
更新日志
2024年09月23日
2024年09月23日
- 周冰倩1995《沧桑情歌》JVC日本录制[WAV+CUE]
- 辛禄乐队.2024-热烈的少年【星辰】【FLAC分轨】
- 成龙.1996-龙的心【滚石】【WAV+CUE】
- 童安格.1991-一世情缘【宝丽金】【WAV+CUE】
- 韩红2010-擦肩而过[央金玛][WAV+CUE]
- RiccardoTesi-UnballoLiscio,Vol.II(2024)[24-48]FLAC
- 金池VS刘罡2009《双声情》[WAV+CUE]
- 冯奥迪《卄》[320K/MP3][67.08MB]
- 冯奥迪《卄》[FLAC/分轨][172.46MB]
- Merryland《Merryland》[320K/MP3][69.48MB]
- 苏芮.1991-停在我心里的温柔【福茂】【WAV+CUE】
- 苏慧伦.2020-面面Every.Side.of.Me【相信音乐】【WAV+CUE】
- 群星.1991-不一样的感觉REMIX【宝丽金】【WAV+CUE】
- 银霞.1983-《你那好冷的小手》珍藏纪念版[WAV分轨]
- 银霞.2002-《国语巨星专辑VOL.3》2CD台湾版[WAV+CUE]