Server Unique Identifier Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David T. Ashley

    Server Unique Identifier Question

    Hi Guys,

    In my application I need a way to generate an identifier that is guaranteed
    to never recur in the lifetime of the server. The method I'm using now is
    to concatentate:

    a)Integer time, in seconds,

    b)Micro time, in microseconds, and

    c)PID

    into one string, then to spin-lock or micro_sleep() until the micro_time
    changes.

    My assumption is that this identifier will be unique because no two
    processes can have the same PID at the same time.

    Is there a better way?

    Thanks, Dave.

    P.S.--Application: Linux, Apache, PHP, MySQL, web database stuff.



  • David Haynes

    #2
    Re: Server Unique Identifier Question

    David T. Ashley wrote:[color=blue]
    > Hi Guys,
    >
    > In my application I need a way to generate an identifier that is guaranteed
    > to never recur in the lifetime of the server. The method I'm using now is
    > to concatentate:
    >
    > a)Integer time, in seconds,
    >
    > b)Micro time, in microseconds, and
    >
    > c)PID
    >
    > into one string, then to spin-lock or micro_sleep() until the micro_time
    > changes.
    >
    > My assumption is that this identifier will be unique because no two
    > processes can have the same PID at the same time.
    >
    > Is there a better way?
    >
    > Thanks, Dave.
    >
    > P.S.--Application: Linux, Apache, PHP, MySQL, web database stuff.
    >
    >
    >[/color]
    Do a google search for uuid to find the proposal by Microsoft. There are
    many Linux implementations of this function.

    -david-

    Comment

    • Sean Barton

      #3
      Re: Server Unique Identifier Question

      maybe doing all that is a little overkill. why not use mt_rand? and if
      you must hash the result. if you use a large enough number for the
      random function you are pretty much looking at a 0 chance of it
      recurring

      hope this helps
      Sean Barton

      Comment

      • noone

        #4
        Re: Server Unique Identifier Question

        David T. Ashley wrote:[color=blue]
        > Hi Guys,
        >
        > In my application I need a way to generate an identifier that is guaranteed
        > to never recur in the lifetime of the server. The method I'm using now is
        > to concatentate:
        >
        > a)Integer time, in seconds,
        >
        > b)Micro time, in microseconds, and
        >
        > c)PID
        >
        > into one string, then to spin-lock or micro_sleep() until the micro_time
        > changes.
        >
        > My assumption is that this identifier will be unique because no two
        > processes can have the same PID at the same time.
        >
        > Is there a better way?
        >
        > Thanks, Dave.
        >
        > P.S.--Application: Linux, Apache, PHP, MySQL, web database stuff.
        >
        >
        >[/color]


        Just curious, but why not use $_SERVER['UNIQUE_ID']?

        M.

        Comment

        • Colin McKinnon

          #5
          Re: Server Unique Identifier Question

          David T. Ashley wrote:
          [color=blue]
          > to never recur in the lifetime of the server. The method I'm using now is
          > to concatentate:
          >
          > a)Integer time, in seconds,
          >
          > b)Micro time, in microseconds, and
          >
          > c)PID
          >
          > into one string, then to spin-lock or micro_sleep() until the micro_time
          > changes.[/color]

          There's not a *better* way, although your proposal is not very efficent (80+
          bits a time / 18 decimal digits). (I would have used a counter with a
          mutex)

          C.

          Comment

          • David T. Ashley

            #6
            Re: Server Unique Identifier Question

            "noone" <noone@nowhere. com> wrote in message
            news:sErFf.2234 4$Jd.12947@news svr25.news.prod igy.net...[color=blue]
            >
            > Just curious, but why not use $_SERVER['UNIQUE_ID']?[/color]

            Thanks for that tidbit. I wasn't aware that this was available.

            From



            I glean that the approach I'm using and the approach Apache is using is
            identical except I use microtime and a spin lock whereas Apache uses a
            counter.

            So, it reinforces my belief that my approach is correct.

            I wasn't aware that Apache does this.

            Thanks!



            Comment

            • David T. Ashley

              #7
              Re: Server Unique Identifier Question

              "Colin McKinnon"
              <colin.thisisno tmysurname@ntlw orld.deletemeun lessURaBot.com> wrote in
              message news:uhuFf.6096 $Dn4.2149@newsf e3-gui.ntli.net...[color=blue]
              >
              > There's not a *better* way, although your proposal is not very efficent
              > (80+
              > bits a time / 18 decimal digits). (I would have used a counter with a
              > mutex)[/color]

              OK, let's say I do "counter with a mutex".

              If I use MySQL to hold the counter, the mutex mechanism is obvious ("LOCK
              TABLE ...").

              However, if I hold the counter in a file, what is the best mutex mechanism
              in PHP?

              Thanks, Dave.



              Comment

              • David Haynes

                #8
                Re: Server Unique Identifier Question

                David T. Ashley wrote:[color=blue]
                > "Colin McKinnon"
                > <colin.thisisno tmysurname@ntlw orld.deletemeun lessURaBot.com> wrote in
                > message news:uhuFf.6096 $Dn4.2149@newsf e3-gui.ntli.net...[color=green]
                >> There's not a *better* way, although your proposal is not very efficent
                >> (80+
                >> bits a time / 18 decimal digits). (I would have used a counter with a
                >> mutex)[/color]
                >
                > OK, let's say I do "counter with a mutex".
                >
                > If I use MySQL to hold the counter, the mutex mechanism is obvious ("LOCK
                > TABLE ...").
                >
                > However, if I hold the counter in a file, what is the best mutex mechanism
                > in PHP?
                >
                > Thanks, Dave.
                >
                >
                >[/color]
                What's wrong with flock()?

                Comment

                Working...