Generating Short Unique Reference Id With PHP Uniqid Function
My objective is to create a unique id attach it to a record and store it in the DB. The id should be alpha - numeric and short. I don not want to use the auto increment way of generating ids as this ID is going to be attached to end of a url so I don't want it to be guessable. After some research I have decided to use uniqid() as i understood that its generated based on time.
My worry is will it be unique across the system and is there a chance for the id to become repeated if i am going scale my system using multiple servers and clustering??
i don't want to do a duplicate check before inserting the value into the DB as this can affect the performance over time as records increase.
I am using Larvel framework. Can anyone suggest any other solution to tackle this problem. I am new to laravel.
Thanks in advance
Thanks for all the suggestions. I have decided to use uniqid() with prefix as user_id. As uniqid() is system time dependent and can cause a conflict when 2 simultaneous requests hit the server, the user_id prefix will make sure that even if simultaneous request comes it will generate different ids since the user_id associated with each request will be different.
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?