Yii2 - POST WebService API and Queue

I’m using yiisoft/yii2-httpclient extension for consuming a web service. i have a controller to create a new record in webservice. for any reason the action create can be fail (timeout, ws is down, and others) it is correct put this action create inside a queue (like the yiisoft/yii2-queue) if the record fails, retry in the background?


public function actionCreate()
        $client = new Client();
        $response = $client->createRequest()
                'name' => $model->name,
                'date' => $model->date,
        if ($response->isOk) {
            return $this->redirect(['index']);

you’ve 3 options here:

  1. To increase the request timeout.
  2. To optimize the web service you’re calling in case you’ve control on. it.
  3. To do the whole job in the background, not only in failure. Having the option to do it in back ground means the user who is. calling your action is calling it like (Fire and Forget).
1 Like

the option 3 is similar to Queue?
thanks! :grinning:

@anasjaghoub i forget say option 3.

1 Like

yes option 3 can. be a queue. but the idea have it for all cases. not only on failure to unify the logic and keep it simple for debug.

1 Like

@anasjaghoub thanks very useful!