How do i execute a command and don’t wait for it to complete?
If i use php exec, how can i include the Yii framework inside my script?
Like a cron command?
defined('YII_DEBUG') or define('YII_DEBUG',true);
// including Yii
require_once('C:\xampp183\htdocs\app\framework\yii.php');
//require_once('../../../framework/yii.php');
// we'll use a separate config file
$configFile='C:\xampp183\htdocs\app\...\protected\commands\cronConfig.php';
Same question here, I need to make this method to be executed inside action
I used this code
public function actionIndex() {
// before going to index, i need it to run the taskes I need.
$url = Url::to(['user/dofile'], TRUE);
exec("php $url > testoutput.php 2>&1 & echo $!", $output);
return $this->render('index');
}
Unfortunately, I think this still runs the command through your web server and thus, locks up your browser until the process is complete. If you want to run something and not have to wait for it to complete, you would have to use something like beanstalkd to queue up your command and execute it in the background. The following article should give you a heads up on how to do this (using pheanstalk):