Question

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.

Was it helpful?

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.

OTHER TIPS

You can use the userid of the users.They will be always unique right?To get more uniqueness try hashing the userid or their email id along with appending the current microtime and use it in the log file.this will be mostly unique even if the user sends repeated requests because the microtime will definitly change between consecutive requests.

$id=$userid.$emailid.uniqid();
$uid=md5($str);

This can be of big problem if used inside small loops.Because inside small loops the microtime barely changes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top