I'm building a platform where precise time sync is critical (+/- 0.01 sec). Based on my (admittedly limited) understanding of AWS, it looks like clock drift between multiple server instances could become a real problem. However, I've been told RDS will not suffer from clock drift even as it scales up. As a result, I'm planning to use RDS when we go live and am trying to always pull now() with a database query instead of just using Carbon::now() (which would pull time from the Apache server). So I guess the preliminary question is: have I missed anything? Is that going to work? Is there a better approach that I've ignored?
Assuming my approach is correct, I'm trying to clean up the following:
$currentTime = DB::select(DB::raw('SELECT NOW()'));
 => stdClass Object
[NOW()] => 2016-05-04 14:03:49
Turns out this is a trickier deal than I originally anticipated. Laravel uses PDO to connect to MySQL. Though MySQL now supports DATETIME with up to 6 places of precision after the decimal, PDO does not support fractions of a second in DATETIME (yeah, "WTF?" is the right response). To retrieve and store data with the precision I'm after, I needed to change gears and use Unix time format (seconds since 1/1/1970). I'm storing that in the database as a DECIMAL(18,3) column to give me room for the millisecond precision I was after.
The code section I described above is now:
$serverTimeArray = DB::select(DB::raw('SELECT UNIX_TIMESTAMP(UTC_TIMESTAMP(3)) AS now')); $serverTime = $serverTimeArray->now;
This actually makes a lot of my time manipulations (add/subtract time) quite a bit easier.
Seems to be working, though I now have a new, unrelated issue I might need to post a different question about...