我有一個訂單的應用程序,其中添加的訂單和更高版本的電子郵件被髮送到訂單的用戶這樣表演時優化yii2 MySQL的性能寫道
if(Yii::$app->request->post()){
//assign model attributes
if($model->save()){
return [
status:true ///notifies the frontend that saved successifully
]
//the below processes are time consuming hence i would like them to queue
$this->sendEmail($model->orderuser);
$this->sendSMS($model->user_no)
}
}
模型保存後,我想發送電子郵件和短信,但這些有時需要相當一段時間因此,我希望返回聲明通知,過程完成後發送郵件和短信
在上述架構後的返回語句其他人不執行?
當我return語句的過程需要一些有價值秒,我怎麼能執行我的計劃return語句後
我」使用
try
/catch
塊之前將它們添加d將它們保存在一個隊列中並寫一個處理所述隊列的cronjob –你對yii2中的隊列有什麼想法嗎?我在laravel中看到過一個,但是沒有關於如何在yii2中實現這一點的線索 –
如果你打算使用隊列,然後有一個最近的擴展版本d你可以使用:http://www.yiiframework.com/news/141/yii-2-queue-extension-released/ – Chinmay