Skip to content

Instantly share code, notes, and snippets.

@ajangrahmat
Created December 3, 2023 06:15
Show Gist options
  • Save ajangrahmat/dbefcaefe17916a4e09f7468afe48df2 to your computer and use it in GitHub Desktop.
Save ajangrahmat/dbefcaefe17916a4e09f7468afe48df2 to your computer and use it in GitHub Desktop.
<?php
// Set header agar dapat melakukan Server-Sent Events
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
include('connection.php');
$query = "SELECT * FROM data";
$result = mysqli_query($conn, $query);
$data = mysqli_fetch_assoc($result);
$data = json_encode($data);
// Kirimkan data dalam format JSON ke klien
echo "data: " . $data;
echo PHP_EOL;
// Event user
echo "event: data";
echo PHP_EOL;
echo PHP_EOL;
flush();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment