Yii Framework Forum

Yii2 queue doesn't work

(tyhja-mitaton) #1

I need to make a delayed email sending, decided to use yii2-queue component for this. But it seem not to work. I’ve been trying to just write some data in file to text it and it stays empty…

The job class:


    namespace app\models;

    use yii\base\Object;

    class WriteJob extends Object implements \yii\queue\Job
        public $text;
        public $file;

        public function execute($queue)
            file_put_contents($this->file, $this->text);

web.php /console.php:

    'aliases' => [
            '@bower' => '@vendor/bower-asset',
            '@npm'   => '@vendor/npm-asset',
    		'@img'   => 'web/i',
    		'@common/mail' => 'mail',
    		'@runtime/queue' => 'runtime/queue',

    'components' => [
    'queue' => [
                'class' => \yii\queue\file\Queue::class,
                'as log' => \yii\queue\LogBehavior::class,
                'path' => '@runtime/queue',



Yii::$app->queue->push(new WriteJob([
			'text' => 'test',
			'file' => Yii::$app->basePath . '/web/file.txt'

The file stays empty. Some runtime data appear though

(Alexander Makarov) #2

Is job executed?

(tyhja-mitaton) #3

It seems no…
There were some .dat files in runtime\queue folder before, but now it’s empty…

(Alexander Makarov) #4

How do you run queue? cronjob or daemon process?

(tyhja-mitaton) #5

Just the code I wrote… I have my yii2 project just locally in OpenServer on windows, so I have no cron… I’ll have to upload it on real linux server later and it should work, I don’t have all permissions on that server…

(Alexander Makarov) #6

Then it’s as it should be. Queue doesn’t execute itself. Run yii queue/run from console. It will exectute scheduled jobs once.

(tyhja-mitaton) #7

Aren’t yii queue/run and Yii::$app->queue ->run() the same thing? Isn’t a way to run it without console? The thing is the project is on open server now and i’ll upload it on real linux server later.

I ran yii queue/listen now, it says “worker is started” but text files remains empty when I call the controller…

(Alexander Makarov) #8

There is no way to run it without console. As far as I know, open server has console as well.

(Alexander Makarov) #9

Do you have job files created?

(tyhja-mitaton) #10

I have some .data files - index.data, job1…job14.data