My code includes the following snippet:
public function query($query)
{
static $seed = 0;
$seed = max($seed + 1, (int)(microtime(true) * 10000));
...
}
This operation succeeds on my machine (i.e., $seed = 14057043101099). On both servers, however, it fails on the first attempt, assigning $seed = 1, after which it succeeds every time.
All three machines are PHP 5.3.X on CentOS 6.5 64-bit. I have tested and confirmed that they all return the correct response for 64-bit integers:
$ php -a
php > echo PHP_INT_MAX;
9223372036854775807
php > echo (int)(microtime(true) * 10000);
14057043101145
The following workaround solved the problem:
public function query($query)
{
static $seed = 0;
$seed = max($seed + 1, round((microtime(true) * 10000)));
...
}
I cannot find any explanation for this behavior. Ideas?