Yes, quite right, web servers like Apache use threads to serve multiple requests. You code is perfect except for hashing.
I think, timestamp,PID and counter are enough to make the filename unique!