Answer the question
In order to leave comments, you need to log in
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
]
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;
}
PHP_BINDIR
does 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 questionAsk a Question
731 491 924 answers to any question