PHP Asynchronous Method Call In The Yii Framework

后端 未结 3 1162
情深已故
情深已故 2021-02-05 22:57

Question

I want to know if it is possible to asynchronously invoke a Yii controller method from one of its actions while the action renders a view, leaving the method

3条回答
  •  执念已碎
    2021-02-05 23:41

    I would try this, though I'm not 100% that Yii will work properly, but its relatively simple and worth a go:

    public function actionCreate() {
        $model = new Vacancies;
        if (isset($_POST['Vacancies'])) {
            $model->setAttributes($_POST['Vacancies']);
            $model->save();
            //I wish :)
        }
    
        HttpResponse::setContentType('text/html');
        HttpResponse::setData($this->render('create', array( 'model' => $model), true);
        HttpResponse::send();
    
        flush(); // writes the response out to the client
    
        if (isset($_POST['Vacancies'])) {
            call_user_func_async('my_long_running_func',$model);
        }
    }
    

提交回复
热议问题