Search code examples
phpmultithreadingtransactionsunique-id

how can i get unique transaction id in PHP?


I'm testing my log module written PHP.

  1. web-server occur too many transaction.
  2. every transaction writing on same file. (log.txt)
  3. how can i logging this transactions at same file with multiple lines?

below log example.

Dec 05 01:50:02 [info] REQ[1111111111111]: param=1

Dec 05 01:50:02 [info] REQ[2222222222222]: param=2

Dec 05 01:50:02 [info] RES[2222222222222]: res=20

Dec 05 01:50:02 [info] RES[1111111111111]: res=10

ok, i found a solution with uniqid().

BUT it based on timestamp, so it is not unique huge request on same time and same machine.

PHP is NOT support THREAD. if other Language (as C,JAVA), best solution is using [thread id] each thread or process, i guess.

any idea on PHP?

sorry for poor english.


Solution

  • First, check if uniqid('', true) provides enough entropy to not have redundancy.

    Secondly, try to track people with sessions. This will allow you to identify people and transactions individually.