K
K
Kolya Vantukh2017-04-05 13:10:56
Yii
Kolya Vantukh, 2017-04-05 13:10:56

How to run a console command in the background (Yii2 )?

I have a socket server that I start manually via the console with the command Yii push. I'm trying to make this command run automatically when I visit the site. Found a widget to work with this https://github.com/vova07/yii2-console-runner-extension , but the error windows cannot find C:\php/php
php environment variable is added.
Here is adding a widget as an app component

'consoleRunner' => [
        'class' => 'vova07\console\ConsoleRunner',
        'file' => '@appRoot/_protected/yii' // or an absolute path to console file
    ]

Here I call it in the controller Here is the run method of the widget
Yii::$app->consoleRunner->run('push');
public function run($cmd)
    {
       
        $cmd = PHP_BINDIR . '/php ' . Yii::getAlias($this->file) . ' ' . $cmd;
        
        if ($this->isWindows() === true) {
           
            pclose(popen('start /b ' . $cmd, 'r'));
        } else {
            pclose(popen($cmd . ' /dev/null &', 'r'));
        }
        return true;
    }

I understand that for some reason it PHP_BINDIRdoes not work properly for me, because How can I solve this problem? I use openserver
$cmd = "C:\php/php /shop/_protected/yii push"

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question