tareq
tareq

Reputation: 1129

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.

Upvotes: 6

Views: 20403

Answers (3)

JotK.
JotK.

Reputation: 101

In yii2, command which worked for me is:

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

Upvotes: 1

Dency G B
Dency G B

Reputation: 8146

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

Upvotes: 11

tareq
tareq

Reputation: 1129

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

Upvotes: 5

Related Questions