3 //プログラムの作成中に複数台の端末を一斉に制御し、更新やページ移動を簡単にできるようにしています。
4 //server.php - 遠隔操作の指令を配信するサーバーサイドプログラムです。
5 header("Content-Type:text/event-stream\n\n");
9 $p=json_decode(file_get_contents('commands.json'),true);
10 $current_cmd=$p[count($p)-1];
11 if($current_cmd['id']!=$last_id&&$current_cmd['time']>=time()-30){
12 echo 'event:'.$current_cmd['action']."\n";
13 echo 'data:'.json_encode($current_cmd)."\n\n";
14 $last_id=$current_cmd['id'];
15 }else if($current_cmd['id']!='dummy'&&$current_cmd['time']<time()-30){
17 file_put_contents('commands.json',json_encode($p));