Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Simple chat app, is there a good simple way to refresh the conversation?

Im making a really basic chat app with textfile as database. I was surprised it worked as im a total copy and paste programmer, but then realized hang on the other person must refresh the page after I type a message.

So I added a header refresh every 3 seconds. But the idea is to have it running for long periods of times. It seemes like a really bad solution to refresh the page considering bandwith. So is there a simple solution?

    header('Refresh: 3; URL=http://example.com/chat.php');

    $handle = fopen("chatlog.txt", "r");
    if ($handle) {
        while (($line = fgets($handle)) !== false) {
            // process the line read.
            echo $line, "<br>";
        }
        fclose($handle);
    }

Comments