Execute command (and don't wait for it to complete)

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




// we'll use a separate config file


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');


But got error message that the link is not found

You should be able to create yii commands and run them off your browser:


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):