简体   繁体   中英

Running a cron in Yii2

I'm using the advanced template application of yii2 and i want to create a cron. I could find only little information while googling the subject and so far found that cron jobs should go in the console folder.

my structure:

backend/
. 
.
.
console/
    models/
        Subscriptions.php   // my custom table model
    .
    .
    .       
    controllers/
        TimelineController.php
    .
    .
    .

I don't know where to go from now or how to proceed? How can I run the cron?

LAMP environment.

In your app\\console\\controllers\\SampleController

class SampleController extends Controller {
        public function actionIndex() {
            echo "cron service runnning";
        }

In your terminal,from your application root folder,run..

   `php yii sample/index`

You should get like cron service runnning

ok i had to navigate to the root of the project in the terminal, there exists a script named yii, i used the following command to run the cron:

php yii cronName.

for example a cron controller named FirstController should be run like this:

rootFolderName/ php yii first

In yii2, command which worked for me is:

          • path/to/php path/to/project/yii command-name

ok i had to navigate to the root of the project in the terminal, there exists a script named yii, i used the following command to run the cron cd rootFolderName/ php yii cronName.

for example a cron controller named FirstController should be run like this:

rootFolderName/ yii first

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM