php:
<?php
header("Cache-Control: no-store");
header("Content-Type: text/event-stream");
while(true){
echo "event: pingn";
echo 'data: testtext';
echo "nn";
// Send a simple message at random intervals.
ob_end_flush();
flush();
sleep(1);
}
?>
html:
<!doctype html>
<html lang="en">
<body>
<h1>PHP SSE demo</h1>
<div id="output"></div>
<script>
var eventSource = new EventSource("sse.php");
eventSource.addEventListener("ping", (event) => {
const output = document.getElementById("output");
output.innerHTML+= event.data;
});
</script>
</body>
</html>
I try to chanage the while loop to if($_SERVER['REQUEST_METHOD']==='POST'){}
, does it mean I can capture all post request and change it on the webpage?
If i use python requests lib to create a http request ,can I display sent content on webpage,am I going in a right direction or i am understanding something wrong.