在Yii2.0中实现计划任务(cron)
以下由我们在信易网络公司开发项目的时候终结出的一些经验
Create console application
创建命令行应用
In advance template there is already a file yii. And there is no need to run it as php, it is Linux script.
在高级模版中的 yii 文件,它是一个 Linux 脚本,不需要使用PHP来运行。
Create cron service command
创建计划任务服务命令
Create a controller in console/controllers
在 console/controllers 文件夹下创建一个控制器
I have created as TestController.php
我创建了一个名为 TestController.php 的文件
<?php
namespace
console\controllers;
use
yii\console\Controller;
/**
* Test controller
*/
class
TestController
extends
Controller {
public
function
actionIndex() {
echo
"cron service runnning"
;
}
public
function
actionMail(
$to
) {
echo
"Sending mail to "
.
$to
;
}
}
This controller should be use the console controller name space
这个控制器应当使用命令行控制器的命名空间
use yii\console\Controller;
How to run it
如何运行
run it as
使用如下方式运行
yii test
I have test it on windows by running
我在 windows 下使用如下方式运行
D:\xampp\htdocs\yii2>d:\xampp\php\php yii test
cron service runnning
D:\xampp\htdocs\yii2>
How to pass params
如何传递参数
yii test/mail [--to="hemctest@gmail.com"]
in windows for test it run as
在 windows 中测试如下
D:\xampp\htdocs\yii2>d:\xampp\php\php yii
test
/mail
[--to=
"hemctest@gmail.com"
]
Sending mail to [--to=hemctest@gmail.com]
官方命令行应用开发文档见此
英文原文: How to implement cron in Yii 2
本文由专注于成都网站建设的信易网络发布,更多关于yii的信息请关注信易网络随后的发布,信易网络的官网http://www.ir58.com
最新文章
- mui框架中底部导航的跳转2
- ASP.NET Core的配置(1):读取配置信息
- Pyhont-Urllib
- 同级兄弟元素之间的CSS控制
- Centos6.5更新e1000网卡驱动
- 调用webservice 417
- ExtJS4.2学习(五)表格渲染与复选框
- VoIP的话音质量测量方法
- Django1.10主题指南—模型
- CAS和ABA问题
- 按键排序JavaScript对象
- [UE4]地图缩放
- Palindrome II
- 【CLR Via C#】2 程序集
- .Net 环境
- openresty/1.11.2.1性能测试
- [整理]SQL Server Reporting Services Charts
- 使用vue与element组件
- LeetCode My Calendar I
- C#异步中的Task,async,await
热门文章
- C#如何转换2位数字表示的年
- HTTPResponse.read([amt]):只能read一次
- 【Android UI设计与开发】之具体解释ActionBar的使用
- 台湾书籍代购网址&mdash;&mdash;2013-08-25 16
- <;BEA-141281>; <;unable to get file lock, will retry ...>; --reference
- 一个卡片式的ViewPager,带你玩转ViewPager的PageTransformer属性!
- 衣联网络-亿能测试 安全测试沙龙 PPT资料免费下载
- MAC上搭建Jenkins + Android + IOS自动开发部署环境
- Java json工具类,jackson工具类,ObjectMapper工具类
- 自己动手实现SharePointList的分页展示