Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a cron in Yii2

Tags:

php

cron

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.

like image 850
tareq Avatar asked Aug 11 '14 06:08

tareq


3 Answers

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

like image 134
Dency G B Avatar answered Nov 19 '22 17:11

Dency G B


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

like image 30
tareq Avatar answered Nov 19 '22 17:11

tareq


In yii2, command which worked for me is:

          • path/to/php path/to/project/yii command-name
like image 1
JotK. Avatar answered Nov 19 '22 16:11

JotK.