在Yii2.0中实现计划任务(cron)_PHP教程

php中文网
发布: 2016-07-13 10:29:36
原创
1201人浏览过

以下由我们在信易网络公司开发项目的时候终结出的一些经验

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 文件夹下创建一个控制器

 

立即学习PHP免费学习笔记(深入)”;

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

使用如下方式运行

Hour One
Hour One

AI文字到视频生成

Hour One 37
查看详情 Hour One

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

 

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/770659.htmlTechArticle以下由我们在信易网络公司开发项目的时候终结出的一些经验 Create console application 创建命令行应用 In advance template there is already a file yii....
相关标签:
yii
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号