A
A
Alexander Shvedov2020-04-13 15:08:38
Laravel
Alexander Shvedov, 2020-04-13 15:08:38

How to know that the transaction goes through 3 times?

$i=0;
        try
        {
         return  DB::transaction(function () use ($p,$i)
            {
                $i++;
                throw new \Exception();

                $patientAnalyzes->delete();
                return response()->json(['message' => 'p успешно удален'.$i], 200);
            }, 3);
        } catch (\Exception $exception)
        {
            return response()->json(['message' => 'Ошибка сервера повторите пожалуйста попытку'.$i], 500);
        }


Why does it show $i 0 how to find out that the transaction tried 3 times and only then crash

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2020-04-13
@constintmid

First, your catch can only work BEFORE all attempts are completed if the error is not a " concurrency error " as they are called in Laravel.
Secondly, if this happened, then it is still impossible to find out the number of the attempt, because as a result, just an exception is thrown without any parameters.
Run a transaction in a loop, catch errors and count attempts.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question