Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default unique id

    Hi there!

    What's the best way to create uids (unique ids) even when runnig at
    exactly same time (microseconds)?

    is this enough ???

    $r = mt_rand();
    $uid = uniqid(getmypid() . $r);

    thanks

    Jan


    Jan Guest

  2. Similar Questions and Discussions

    1. Unique Form inserting into many tables using unique id
      I have a Registration Form that have 3 steps. The data could be inserted into many (4) tables. Some data corresponding to a one table (the main or...
    2. Unique id on form
      Hi, Our site is joining an affiliate program and we have a form where the user goes in and fill out. I need to gather that an email address the...
    3. Unique yet Eerie
      I'm have a strange problem. I've encoutered a few before, but nothing like this: New machine with php4.2.2 on RedHat with Apache2.0 All my...
    4. Which Unique Sort From FAQ Is Better?
      Also sprach Chinadian: Those two don't do the same thing. Both will uniquify the list, but only b) will sort them. The result of these two will...
    5. Unique Records in asp
      Hi, How can I count only unique records in a recordset? (sql server 7.0). When I do a select query for an asp page, I may have more than 1...
  3. #2

    Default Re: [PHP] unique id

    Hi,

    Saturday, July 26, 2003, 5:58:41 PM, you wrote:
    j> Hi there!

    j> What's the best way to create uids (unique ids) even when runnig at
    j> exactly same time (microseconds)?

    j> is this enough ???

    j> $r = mt_rand();
    j> $uid = uniqid(getmypid() . $r);

    j> thanks

    j> Jan


    I use:

    $id = md5(uniqid(rand(),1));

    --
    regards,
    Tom

    Tom Rogers Guest

  4. #3

    Default Re: [PHP] unique id

    * Thus wrote jan (jan@plazma.sk):
    > Hi there!
    >
    > What's the best way to create uids (unique ids) even when runnig at
    > exactly same time (microseconds)?
    >
    > is this enough ???
    >
    > $r = mt_rand();
    > $uid = uniqid(getmypid() . $r);
    If you're running a cluster of machines I would include information
    on the machine that is generating the uid.

    $uid = uniqid(getmypid() . $r . '_MACHINE_NAME_');

    Curt
    --
    "I used to think I was indecisive, but now I'm not so sure."
    Curt Zirzow Guest

  5. #4

    Default Re: [PHP] unique id

    * Thus wrote Gabriel Guzman (gabe@careercast.com):
    > On Sat, 2003-07-26 at 07:11, Curt Zirzow wrote:
    > > * Thus wrote jan (jan@plazma.sk):
    > > > Hi there!
    > > >
    > > > What's the best way to create uids (unique ids) even when runnig at
    > > > exactly same time (microseconds)?
    > > >
    > > > is this enough ???
    > > >
    > > > $r = mt_rand();
    > > > $uid = uniqid(getmypid() . $r);
    > >
    > > If you're running a cluster of machines I would include information
    > > on the machine that is generating the uid.
    > >
    > > $uid = uniqid(getmypid() . $r . '_MACHINE_NAME_');
    > >
    > > Curt
    >
    > this is similar to what we do as well:
    >
    > hexadecimal timestamp + hexadecimal pid + hexadecimal randomvalue + hex
    > ip address of server (only used if using multiple machines, otherwise
    > this part is left off).
    >
    > I've also considered using semaphores in my id generation function to
    > insure only one counter can be created at a time, but am worried that
    > this might cause a bit of a performance hit. Anyone tried this?
    The only other way I have done it was to make a central database
    with a table containing a auto incremented id. All scripts
    would add a record and get back the auto incremented id number.
    Since db inserts are atomic, it is guaranteed to be unique.

    I think the biggest weak point in this approach is if the
    connection goes down between the web server and db server, the
    script is left clueless as what to do.


    Curt
    --
    "I used to think I was indecisive, but now I'm not so sure."
    Curt Zirzow Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139