Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/spatie/first-or-create-racing-condition-demo
A demo Laravel app to demonstrate the dangers of using firstOrCreate in a queued environment
https://github.com/spatie/first-or-create-racing-condition-demo
eloquent laravel php queues
Last synced: 2 months ago
JSON representation
A demo Laravel app to demonstrate the dangers of using firstOrCreate in a queued environment
- Host: GitHub
- URL: https://github.com/spatie/first-or-create-racing-condition-demo
- Owner: spatie
- Created: 2018-06-19T21:46:38.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-03-09T16:22:21.000Z (almost 3 years ago)
- Last Synced: 2024-05-09T22:24:36.516Z (9 months ago)
- Topics: eloquent, laravel, php, queues
- Language: PHP
- Homepage: https://freek.dev/1087-breaking-laravels-firstorcreate-using-race-conditions
- Size: 1.48 MB
- Stars: 7
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://supportukrainenow.org)
# A demo Laravel app to demonstrate the dangers of using firstOrCreate in a queued environment
Read [this blogpost on murze.be](https://murze.be/breaking-laravels-firstorcreate-using-race-conditions) first to get familiar with the problem.
## Support us
[](https://spatie.be/github-ad-click/first-or-create-racing-condition-demo)
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
## Usage
To run this demo you'll need to have Redis installed
1. Clone the repo
2. Install the dependencies with `composer install`
3. Copy `.env.example` to `.env`
4. Create a `racing_condition_demo` database
5. Run `php artisan key:generate`
6. Run `php artisan migrate`
7. In a seperate terminal start Horizon with `php artisan horizon`
8. Run `php artisan create-products`If you look in the `products` table of the database multiple records with the same uuid will have been created.