How to call a console command in web application a

2019-02-07 00:09发布

I have a console command to do a consumer time, AND I need to know how to call (execute) it in a web application action in YII.

class MyCommand extends CConsoleCommand{
      public function actionIndex(){
          $model = new Product();
          $model->title = 'my product';
          ...
          $model->save();
          .
          .
          .
      }
}

I want to execute this code.

7条回答
叼着烟拽天下
2楼-- · 2019-02-07 00:41

Try this

Yii::import('application.commands.*');
$command = new GearmanCommand('start', Yii::app()->commandRunner);
$command->run(array('start', '--daemonize', '--initd'));

where array('start', '--daemonize', '--initd') is a action and action parameters

查看更多
登录 后发表回答