php - compare client device clock with server clock exactly upto milliseconds -


i finding way difference between client clock , server clock.

till have tried following approach.

collecting:

  1. client request time
  2. server time
  3. client response time

the problem unknown delay between request reach server , response reach client.

here's implementation of scheme using javascript , php:

time.js

var request = new xmlhttprequest(); request.onreadystatechange = readystatechangehandler; request.open("post", "http://www.example.com/sync.php", true); request.setrequestheader("content-type", "application/x-www-form-urlencoded"); request.send("original=" + (new date).gettime());  function readystatechangehandler() { var returned = (new date).gettime(); if (request.readystate === 4 && request.status === 200) {     var timestamp = request.responsetext.split('|');     var original = + timestamp[0];     var receive = + timestamp[1];     var transmit = + timestamp[2];     var sending = receive - original;     var receiving = returned - transmit;     var roundtrip = sending + receiving;     var oneway = roundtrip / 2;     var difference = sending - oneway; // want     // server time client time + difference } } 

sync.php

<?php $receive = round(microtime(true) * 1000); echo $_post["original"] . '|'; echo $receive . '|'; echo round(microtime(true) * 1000); ?> 

even approach 50-500 ms error. if delay high, error more.

but wonder how company named "adtruth" claims able differentiate devices based on clock time. call "time differential linking" key device recognition adtruth-style patented technology called tdl, time-differential linking. while in billions of connected devices there may thousands same configuration, no 2 have clocks set same time -- @ least, not when take down millisecond. says ori eisen, founder of 41st parameter , adtruth, "we take these disparate time stamps , compare them server master clock. if there doubt, tdl tie-breaker."

http://www.admonsters.com/blog/adtruth-joins-w3c-qa-ori-eisen-founder-and-chief-innovation-officer

here link "time differential linking" patent

http://www.google.com/patents/us7853533

var oneway = roundtrip / 2; 

why assume network symmetrical? it's reasonable assumption - try calibrate connection send data in both directions estimate of throughput , latency (see boomerang's bw module example of server-client measurement) basic feature of tcp congestion window adapts progressively - , hence on static connection, throughput changes markedly in stages of connection (exactly point @ you're try , capture client device identity).

do try make sure response less 1kb including headers (to make sure fits in single packet) , keep alive enabled. request smaller post, although using websockets give more accurate figure.

a more realistic approach capture several samples @ known intervals capturing calculating average, e.g.

estmatedrtt=300; (var x=0; x<10; x++) {     settimeout(estimatedrtt * x * 1.3, captureoffset); } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -