0

i have the following line of code

$timestamp = '-'.(int)(microtime(true)*1000);

$timestamp gets appended onto the end of an order id to make it more unique, however, while i was testing on my local Wamp Server (on a Windows OS) i was getting values like this

-166776478
-166701036

as a test, i went and did order on a test server which is on unix, and i was getting values like this

1372722035
1372722471

for the last one in each what i did was open 2 firefox windows and did the orders almost at the same time (my local wamp server took a bit longer cause i didn't have any caching on

now, the weird thing is that i was expecting the values on my local Wamp server would be roughly the same as that as the test server

from my understanding microtime() eturns the current Unix timestamp since the Unix epoch with microseconds so timezone settings shouldn't have any affect

i'm wondering does microtime get different values if it's not running on unix and if not why am i getting 2 very different values

Memor-X
  • 2,870
  • 6
  • 33
  • 57
  • 1
    whats wrong with php's uniqid() –  Jul 02 '13 at 00:08
  • @Dagon no idea, the system was done by someone else, my system runs off from data they send out, i would guess performance since `microtime` is just getting the timestamp while `uniqid` is returning a unique valuse based off from the timestamp which would probably need more processing, i could change it but i would want to avoid changing a system that existed long before mine unless i really have to, anyway, i don't think the difference in values is causing any problems so this is just curiosity – Memor-X Jul 02 '13 at 00:26

1 Answers1

2

My guess what is happening is that on windows machine you are are overflowing the maximum value that can be represented as a integer.

Check the value of PHP_INT_MAX on both environments (echo PHP_INT_MAX;) The problem has probably less to do with windows vs linux and more to do with 32bit vs 64bit.

Orangepill
  • 24,500
  • 3
  • 42
  • 63
  • yeh that seems to be the problem, while my machine which wamp is installed into and the test server are both have 64bit OSs the values of `PHP_INT_MAX` are different, i think the reason is that i might have a 32bit version of wamp so that's being used over the 64bit Windows 7 – Memor-X Jul 03 '13 at 01:16