Anyone help me, please!. In my project, i have transaction with lock record:
namespace App\Console\Commands;
use Illuminate\Console\Command;
class Testing extends Command {
protected function handling()
{
DB::beginTransaction();
try {
$posts = Posts::lockForUpdate()->find(1);
//run step 1
//run step 2
//run step 3
} catch (\Exception $e) {
DB::rollback();
}
}
}
in my case, i call it from command, when it running:
php artisan test:run
...
running step 1
...
...
running step 2
..
..
Ctrl C
-> quit command.
Transaction not commit and lock record forever.
Can i commit transaction on command force quit?
If you are using DB::beginTransaction();
then you need to commit using DB:commit();
as
DB::beginTransaction();
try {
$posts = Posts::lockForUpdate()->find(1);
//run step 1
//run step 2
//run step 3
DB::commit();
} catch (\Exception $e) {
DB::rollback();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.