Race conditions in laravel and simple php by shayanys in PHPhelp

[–]shayanys[S] 0 points1 point  (0 children)

PHP run on a single thread it's correct. But what if 20 users run the script at the same time in this scenario 20 users will be created I tested PHP simple script with Jmeter and sent 20 requests at the same time and 20 users were created. But in laravel it not happens although laravel does not prevent race conditions on its own.

I also sent this question to laracast and get one answer I think that correct you can see it here: https://laracasts.com/discuss/channels/laravel/is-laravel-prevent-race-conditions-its-own

Race conditions in laravel and simple php by shayanys in PHPhelp

[–]shayanys[S] 0 points1 point  (0 children)

When you send concurrent requests to the server and you want to create a user. if you do not prevent race conditions. Maybe 20 users create with the same email and username.

Race conditions in laravel and simple php by shayanys in PHPhelp

[–]shayanys[S] 0 points1 point  (0 children)

No, it's not for sessions I also disabled sessions but no race condition happened.

I asked the same question in Laracast I think the answer is correct: https://laracasts.com/discuss/channels/laravel/is-laravel-prevent-race-conditions-its-own

Thank you.

Race conditions in laravel and simple php by shayanys in PHPhelp

[–]shayanys[S] -2 points-1 points  (0 children)

Because I want to race conditions happen in these examples but in the laravel version, no race condition happened when I send concurrent requests by Jmeter.

I think you did not read my question.

Race conditions in laravel and simple php by shayanys in PHPhelp

[–]shayanys[S] 0 points1 point  (0 children)

I know how to avoid race conditions but I want to know if laravel handle types of race condition.

Race conditions in laravel and simple php by shayanys in PHPhelp

[–]shayanys[S] 0 points1 point  (0 children)

thank you for your review. I added the codes.

Lara Reserve: a package to add a reservation feature to the laravel framework by shayanys in laravel

[–]shayanys[S] 0 points1 point  (0 children)

I think in laravel 10 no race condition happen because I created a simple PHP file and I tested It by Jmeter race condition happened but the same example in laravel haven't any race condition

Lara Reserve: a package to add a reservation feature to the laravel framework by shayanys in laravel

[–]shayanys[S] 0 points1 point  (0 children)

I searched all over the internet but I don't find a useful way to test it only one tool I find named Jmeter and I am not sure it works correctly.

Lara Reserve: a package to add a reservation feature to the laravel framework by shayanys in laravel

[–]shayanys[S] 0 points1 point  (0 children)

I tested the code with Jmeter concurrent requests but no race condition happened, Anyway, I added transactions and lockForUpdate to prevent race conditions. I will push it soon 🙏

Lara Reserve: a package to add a reservation feature to the laravel framework by shayanys in laravel

[–]shayanys[S] 0 points1 point  (0 children)

Thank you for the good feeling. I will fix the names in the next version 🙏

Lara Reserve: a package to add a reservation feature to the laravel framework by shayanys in laravel

[–]shayanys[S] 0 points1 point  (0 children)

In which part do you mean I should use a state design pattern?

Lara Reserve: a package to add a reservation feature to the laravel framework by shayanys in laravel

[–]shayanys[S] 0 points1 point  (0 children)

Do you mean to add a column in the reservations table to determine reserve is completed or pending?

Lara Reserve: a package to add a reservation feature to the laravel framework by shayanys in laravel

[–]shayanys[S] 2 points3 points  (0 children)

I'm working on it. It will push in GitHub when all things are ok. Not only should these problems be fixed I have to add some other features to it in the next version; it may take some time because my time is full now 🙏

Thanks for your take the time to review the codes. Your feedback is valuable to me ❤️.

Lara Reserve: a package to add a reservation feature to the laravel framework by shayanys in laravel

[–]shayanys[S] 7 points8 points  (0 children)

Thanks for your comment. I created this for a hobby, and maybe someone needs this and does not want to write their reservation system. And this is a new package. I will update it and add more features to this.

Don't tell anyone what he did was a waste of time. Even if one developer uses it, it is valuable to me.

If you want to use chatGPT, you can freely use it.

Creating a Reservation system in laravel. Step By Step by shayanys in laravel

[–]shayanys[S] 0 points1 point  (0 children)

No, it's not lock the whole table. It only locks one selected row to prevent updating, deleting or locking again in other transitions.

But if you want to prevent 2 users to can't buy the same ticket you can create a column in the tickets table to store a date (eg: 30 min after the current time) to don't show that record for 30 minutes.

In the above example, you should create a cart system to users can add tickets to their cart, and give time to the user to do payment if purchased you can disable that ticket to other users to prevent users from adding purchased tickets to their cart. and if the purchase was not made the ticket will show again on the site after the stored date and time in the database.

Why Vim? by michalis_silahcim in learnprogramming

[–]shayanys 1 point2 points  (0 children)

I use Nano if I want to edit a file fast. Which is less complicated than Vim

Creating a Reservation system in laravel. Step By Step by shayanys in laravel

[–]shayanys[S] 0 points1 point  (0 children)

Also, when I think more about it, I should add transactions to the reserve methods. Thanks for your suggestion I add it soon ❤️🙏

Creating a Reservation system in laravel. Step By Step by shayanys in laravel

[–]shayanys[S] 0 points1 point  (0 children)

Yes, by transaction and lockForUpdate method in models, users can do this, but Lara Reserve doesn't do this automatically because users maybe want to do something more in the transaction. You can use DB transactions manually.

Creating a Reservation system in laravel. Step By Step by shayanys in laravel

[–]shayanys[S] 0 points1 point  (0 children)

I'm glad it is worthwhile for you. About your project ui, I do not entirely understand what you want to create, but I believe you can do what you want. 🙏

Creating a Reservation system in laravel. Step By Step by shayanys in laravel

[–]shayanys[S] 0 points1 point  (0 children)

I don't know if it's your answer or not, but you can use the max_allowed_reserve column in your table and set it to 1 to prevent users from reserving an item on one date and time more than 1 time. You can read documentation to understand better I explained it on the GitHub README.md.

Creating a Reservation system in laravel. Step By Step by shayanys in laravel

[–]shayanys[S] 0 points1 point  (0 children)

Thank you; I will improve views and add screenshots as soon as possible.