我正在尝试使用yii2-queue https://github.com/yiisoft/yii2-queue/blob/master/docs/guide/usage.md
它说:
要使用扩展,您必须像下面这样配置它:
return [ 'bootstrap' => [ 'queue', // The component registers its own console commands ], 'components' => [ 'queue' => [ 'class' => \yii\queue\<driver>\Queue::class, 'as log' => \yii\queue\LogBehavior::class, // Other driver options ], ], ];
我的问题很简单:在哪个PHP文件中,我应该把这段代码放在哪个目录中?
注意:我使用的是Basic模板。
对于Yii2基本模板config/console.php
对于Yii2高级模板console/config/main.php
return [
'bootstrap' => [
'log',
'queue',
],
'components' => [
'queue' => [
'class' => \yii\queue\db\Queue::class,
'db' => 'db', // DB connection component or its config
'tableName' => '{{%queue}}', // Table name
'channel' => 'default', // Queue channel key
'mutex' => \yii\mutex\MysqlMutex::class, // Mutex that used to sync queries
'as log' => \yii\queue\LogBehavior::class,
// 'deleteReleased' => YII_ENV_PROD,
],
]
];
添加到后端或前端的main.php文件中,你正在使用像这样的qazxsw poi
'bootstrap' => ['log', 'queue'],
要使其工作,您需要在console /config/main.php文件中执行相同操作并运行命令listen form documentaiton
在yii2 basic上配置它非常简单,在config / web.php文件中添加以下配置,如果你使用前端则为yii2高级,然后在frontend / config / main.php中添加,如果你使用后端然后添加to backend / config.main.php。
像这样
Add this to under component array
'queue' => [
'class' => Queue::class,
'db' => 'db', // DB connection component or its config
'tableName' => '{{%db_queue}}', // Table name
'channel' => 'default', // Queue channel key
'mutex' => MysqlMutex::class, // Mutex used to sync queries
]