Home >Backend Development >PHP Tutorial >Implementing scheduled tasks (cron) in Yii2.0_PHP tutorial

Implementing scheduled tasks (cron) in Yii2.0_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:29:36953browse

The following are some of the experiences we gained when developing projects at Xinyi Network Company

Create console application

Create a command line application

In advance template there is already a file yii. And there is no need to run it as php, it is Linux script.

The yii file in the advanced template, it is a Linux script and does not require PHP to run.

Create cron service command

Create scheduled task service command

Create a controller in console/controllers

Create a controller in the console/controllers folder

I have created as TestController.php

I created a file called TestController.php

<?php

namespace consolecontrollers; use yiiconsoleController; /** * 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

This controller should use the command line controller namespace

use yiiconsoleController;

How to run it

How to run

run it as

Use the following method to run

yii test

I have test it on windows by running

I run it in windows as follows

D:xampphtdocsyii2>d:xamppphpphp yii test

cron service runnning D:xampphtdocsyii2>

How to pass params

How to pass parameters

yii test/mail [--to="hemctest@gmail.com"]

in windows for test it run as

Test in windows as follows

D:xampphtdocsyii2>d:xamppphpphp yii test/mail [--to="hemctest@gmail.com"]

Sending mail to [--to=hemctest@gmail.com]

The official command line application development documentation can be found here

Original English text: How to implement cron in Yii 2

This article is published by Xinyi Network, which specializes in website construction in Chengdu. For more information about yii, please pay attention to Xinyi Network’s subsequent releases. Xinyi Network’s official website is http://www.ir58.com

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/770659.htmlTechArticleThe following are some of our experiences when developing projects at Xinyi Network CompanyCreate console application Create a command line application In advance template there is already a file yii....
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn