Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7647631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:30:41+00:00 2026-05-31T10:30:41+00:00

I need to start same task on different tabs/browsers/clients at the same exact time.

  • 0

I need to start same task on different tabs/browsers/clients at the same exact time. As close as possible (same second, even millisecond).

What I have right now

-Both clients are sending request to server via AJAX when they start the website.

-Server is taking current timestamp (seconds) and removes it from 10 seconds. Then sends back remaining time to clients.

-Clients receive remaining time, generate timestamp, add remaining time to current time and wait till it is same or greater, then start’s task.

PHP (Server)

<?php
// Remove dot on timestamp
$timeStamp = str_replace('.', '', microtime(true));

// Make it same as JS one (13 symbols)
if (strlen($timeStamp) > 13) {
    $timeStamp = substr($timeStamp, 0, -1);
}

// I want last 4 digits - 1st is second, rest 3 are microseconds
$timeStamp = substr($timeStamp, 9, 4);

// Remove time from 10 seconds and we get how many seconds left till start (meaning we start task every 10 seconds on server)
echo 10000 - $timeStamp;

JS (Client)

$.get('ajax.php', function(data){
    // Current date
    var newDate = new Date().getTime();

    // Start date
    playDate = newDate + parseInt(data);

    // Waiting for current date to be same or greater than start date
    while (true){
        if (playDate <= new Date().getTime()){
            alert('DONE'); // It is pretty close, but not excatly
            break;
        }
    }
});

My question(s)

-Am I going the right way?

-Is this the only way of doing this?

-Can it be done better?

-How can I minimize time difference between different computers/browsers/tabs.

I imagine that I should take into consideration request/response times and do some calculations with them but before I continue I want to make sure that there is no other, better way of achieving my goal and that I’m not going terribly wrong with this solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:30:42+00:00Added an answer on May 31, 2026 at 10:30 am

    You should use setTimeout() and not a busy loop like that, and you should adjust your expectations and realize that without complete control of the client machines you can’t expect very close synchronization.

    Even if you were to measure network latency, that’s not necessarily accurate, as it can change suddenly due to fluctuations in traffic etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to start a program every time the user logs in, but I
Why do Perl variables need to start with different characters (sigils)? Scalar variables start
I need to notify 1-many clients to perform a task (reload). The server may
I need start off with code because I am not sure what terminology to
I need to start a Visual Basic script file by using WMI in a
I need to start a Unix process by calling a PHP-page through the web.
I need to start a copy of a Rails app from within Java. I
I need to start NSTimer by 0:0:0 that I am doing and I have
I need to start a project that will be json-API-centric, which means that most
I want to (need to) start a sub-process from a perl script that checks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.