2

I stumbled upon a rather strange site the other day : https://harmless.herokuapp.com/main

It is an online mini chat that does not use javascript on the client side, and yet it allows you to display your messages and those of others, in real time.

While trying to document myself I came across the term "Long Polling" but all the sources I could look at used javascript to implement it.

I guess the forever loading page is something to do with it. From what I understand, if a valid XMLHttpRequest is not returned, then the client-side browser never closes the connection with the server and keeps trying to receive data. I tried the code below but it didn't work : How do I implement basic "Long Polling"?

<?php

if(rand(1,3) == 1){
    /* Fake an error */
    header("HTTP/1.0 404 Not Found");
    die();
}

/* Send a string after a random number of seconds (2-10) */
sleep(rand(2,10));
echo("Hi! Have a random number: " . rand(1,10));

?>

In short, I wanted to understand how a site could update the data received and send it back to the user in real time without using client-side javascript.

EDIT :

Here is the answer : github.com/kkuchta/css-only-chat

Thank you to Flux for his find!

  • Try PHP sockets, long polling will make your server unable to handle other requests, according to https://stackoverflow.com/questions/333664/how-do-i-implement-basic-long-polling – Ameer Apr 22 '20 at 16:38
  • While it's probably _technically_ possible, it will be ugly to write, ugly to look at, and perform like trash. Use Javascript. – Sammitch Apr 22 '20 at 16:54
  • Related: https://github.com/kkuchta/css-only-chat – Flux Apr 22 '22 at 13:48
  • omg after 2 years I finally understood how it was possible and it's all thanks to you. Thank you so much!!! – Random_name_1 May 12 '22 at 21:15

0 Answers0