Answer the question
In order to leave comments, you need to log in
How to implement automatic page refresh on file change?
Good afternoon!
On the server in the directory frontend/web/files/
is the test.json file. The file is automatically updated ~ 1 time per half hour.
The controller reads the file data for the report:
public function actionReport(){
$file = file_get_contents('http://site.ru/files/test.json');
for ($i = 0; $i <= 31; ++$i) {
$file = str_replace(chr($i), "", $file);
}
$file = str_replace(chr(127), "", $file);
if (0 === strpos(bin2hex($file), 'efbbbf')) {
$file = substr($file, 3);
}
$content = json_decode($file, true);
return $this->render('report', [
'content' => $content,
]);
}
Answer the question
In order to leave comments, you need to log in
ajax + https://php.ru/manual/function.filemtime.html
or
websocket + https://php.ru/manual/function.filemtime.html
I strongly recommend checking not by the contents of the file, but by the time it was changed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question