1. Go to this page and download the library: Download urbanindo/yii2-queue library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
'components' => [
'db' => [
// the db component
],
'queue' => [
'class' => 'UrbanIndo\Yii2\Queue\Queues\DbQueue',
'db' => 'db',
'tableName' => 'queue',
'module' => 'task',
// sleep for 10 seconds if there's no item in the queue (to save CPU)
'waitSecondsIfNoQueue' => 10,
]
]
class FooController extends UrbanIndo\Yii2\Queue\Worker\Controller
{
public function actionBar($param1, $param2)
{
echo $param1;
}
}
class FooController extends UrbanIndo\Yii2\Queue\Worker\Controller
{
public function actionBar($param1, $param2)
{
try {
// do some stuff
} catch (\Exception $ex) {
\Yii::error('Ouch something just happened');
return false;
}
}
}
public function behaviors()
{
return [
[
'class' => \UrbanIndo\Yii2\Queue\Behaviors\DeferredEventBehavior::class,
'events' => [
self::EVENT_AFTER_VALIDATE => 'deferAfterValidate',
]
]
];
}
public function deferAfterValidate()
{
// do something here
}