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 runnning
D:\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....