Implementing a Scheduled Task (cron) _php Tutorial in Yii2.0

Source: Internet
Author: User

The following are some of the experiences that we end up with when we develop a project at Shun Yi Network.

Create Console Application

Create a command line app

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

The Yii file in the advanced template, which is a Linux script, does not need to be run with PHP.

Create Cron Service Command

Create a Scheduled Task Service command

Create a controller in Console/controllers

Create a controller under the Console/controllers folder

I have created as testcontroller.php

I created a file named testcontroller.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 is use the console controller name space

This controller should use the command line controller's namespace

use yii\console\Controller;

How to run it

How to Run

Run it as

Run using the following method

yii test

I have the test it on the windows by running

I am running under Windows using the following method

D:\xampp\htdocs\yii2>d:\xampp\php\php yii test

cron service runnningD:\xampp\htdocs\yii2>

How to pass params

How to pass Parameters

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

In the Windows for test it run as

Test the following in Windows

D:\xampp\htdocs\yii2>d:\xampp\php\php yii test/mail[--to="hemctest@gmail.com"]

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

Official command line application development documentation see this

The original English: How to Implement Cron in Yii 2

This article by the focus on the Chengdu website Construction of the letter Easy network release, more information about Yii please pay attention to the letter easy network subsequent release, the letter Easy Network's official website http://www.ir58.com

http://www.bkjia.com/PHPjc/770659.html www.bkjia.com true http://www.bkjia.com/PHPjc/770659.html techarticle The following are some of the experiences that we have brought to an end when we develop a project at the Shin-networking company Create console application creates a command line application in advance template there is already a file yii....

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.