如何让网站上的每个访问者都在音频文件的同一点来模拟预定的直播流?

I am attempting to simulate a scheduled live audio stream without the use of any third party tools/software. In order to do so, I would need every visitor on the website to be on the same point on the audio file. My initial plan was to have a PHP script that keeps track of the time, and write to a .json file :

ini_set('max_execution_time', 0);
include 'mp3file.class.php';
$file = "./audioDuration.json";

$mp3file = new MP3File("Nightride.mp3");
$duration = $mp3file->getDurationEstimate();

$tracker = 0;
while($tracker < $duration){
    $tracker++;
    file_put_contents($file, $tracker);
    sleep(1);
}

And the Javascript :

$.getJSON( "audioDuration.json",
    function( returnedData ) {
        document.getElementById('audioElement').currentTime = returnedData;
}

However, being completely new to PHP, I did not realize that any user can run this script on their own browser, and it would cause the audioDuration.json to contain the wrong data. I've done some research, and it appears that there are ways to have a PHP script only run if the server requests it. I am not sure if this is the most practical way to accomplish this.

I feel you should use a server side resource to be sure any client get the same "time" to set-up your audio file.

Why don't you use something like server date('H:i:s); function. If you get a 1hour long file you just need to dont take care about hours, and use only minutes and seconds to get which time should be used to start the audio file.

And you don't even need to use javascript to call server to get the value. If you use php to generate your HTML you can directly print value in the HTML's javascript when loading the page, something like :

echo '<script type="text/javascript">
    document.getElementById('audioElement').currentTime = ' . $timer . ';
</script>';