update chat
Deploy / Deploy (push) Successful in 40s

This commit is contained in:
www-data committed 2025-03-27 09:59:15 -03:00
1 parent e28a164a5c
commit 756d2a98b2
3 files changed
+136 -126

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
<?php
if (!isset($_GET['user'])) {
http_response_code(400);
exit("Missing user");
}
$user = preg_replace('/[^a-zA-Z0-9_-]/', '', $_GET['user']);
header("Content-Type: text/event-stream");
header("Cache-Control: no-cache");
header("Connection: keep-alive");
$tmp_file = sys_get_temp_dir() . "/relay_chat_{$user}.txt";
if (!file_exists($tmp_file)) {
file_put_contents($tmp_file, '');
}
$last_modif = 0;
while (true) {
clearstatcache();
$current_modif = filemtime($tmp_file);
if ($current_modif > $last_modif) {
$last_modif = $current_modif;
$data = file_get_contents($tmp_file);
echo "data: " . trim($data) . "\n\n";
ob_flush();
flush();
}
sleep(1);
}
?>