code: public function writeSession($id, $data)
      {
          // exception must be caught in session write handler
          // http://us.php.net/manual/en/function.session-set-save-handler.php
          try {
              $query = new Query;
              $exists = $query->select(['id'])
                  ->from($this->sessionTable)
                  ->where(['id' => $id])
                  ->createCommand($this->db)
                  ->queryScalar();
              $fields = $this->composeFields($id, $data);
              if ($exists === false) {
                  $this->db->createCommand()
                      ->insert($this->sessionTable, $fields)
                      ->execute();
              } else {
                  unset($fields['id']);
                  $this->db->createCommand()
                      ->update($this->sessionTable, $fields, ['id' => $id])
                      ->execute();
              }
          } catch (\Exception $e) {
              $exception = ErrorHandler::convertExceptionToString($e);
              // its too late to use Yii logging here
              error_log($exception);
              echo $exception;
  
              return false;
          }
  
          return true;
      }
docs: Session write handler.
  Do not call this method directly.
  @param string $id session ID
  @param string $data session data
  @return boolean whether session write is successful