我找到了最好的解决方案:yii的runactions扩展
这是扩展程序,可让您从控制器后台操作运行。有几种使用方法。对于我来说,最好的方法是
public function actionTimeConsumingProcess()
{
if (ERunActions::runBackground())
{
//do all the stuff that should work in background
mail->send()
}
else
{
//this code will be executed immediately
//echo 'Time-consuming process has been started'
//user->setFlash ...render ... redirect,
}
//User information
echo "Submit Success!"
}
并且它的工作但没有ajax请求,当我发出ajax请求时,由于某种原因它不起作用。所以我用了:
ERunActions::httpPOST($this->createAbsoluteUrl('Form/Submit'), array('to'=>'mail@domain.com', 'subject'=>'This is the subject'));
它的工作很棒,但不是理想的解决方案。