Are you accounting for connection times and lag? If you're using AJAX, you need to make sure you use a time offset for the length of time it takes to connect and download the response:
var XHR = new XMLHttpRequest();
var Now = new Date().getTime();
XHR.open("GET", "/datetime.php", true);
XHR.onreadystatechange = function()
{
if (XHR.status == 200 && XHR.readyState == 4)
{
// How long did it take to get here?
var TimeOffset = new Date().getTime() - Now;
// ... your code to get the date from the response goes here
// Now add the TimeOffset variable to the date
var SyncTime = new Date().setTime(PHPTime + TimeOffset);
}
}
XHR.send();
Of course, that code's just to give you a general idea and will probably need adjusting to account for timezone offsets etc.