Hello guys, I have this school project. There is one aspect that I'm not sure of.
So, here's the project description. The project is chatting. Well, you know how chatting works. When I type a message, that message will appear on the other person's computer.
Anyway, the part wherein Im not sure of is how this appearing of message to the other computer works. I have a cable wire that will connect two computers. If I run my server, and I and my partner will chat, do I need some networking php code or just the normal ones?
Anyway, I'm not really sure how this works, I need some help from you experts.

Here is a bit chat script.

<form method="post">

<?php

if (isset($_POST['chat']) && trim($_POST['chat'])) {
  file_put_contents('chat.txt', $_POST['chat'] . "\n", FILE_APPEND);
}

echo @implode('<br />', @file('chat.txt')) . '<br />';


?>

<input name="chat" />
<button type="submit">Send</button>
<button type="submit">Refresh</button>

</form>

This is meant to learn from, nothing else. You need JavaScript to retrieve new data without reloading the page so it is left out.

With this example, a PHP page is just displaying data it reads from a file, and writes new messages to that file. If developing a chat in PHP, you'll most likely be writting messages to temporary storage, like a database, or file, then just reading those messages back to the pages the users are on.

To show separate messages for different users, you employ sessions. This of course a different topic.

Most large scale chat systems do not work this way however. They do not save any messages at all. They only route the messages. This way they don't have to wait for the messages being written to some storage and can process messages asynchronously (in parallel without waiting).

Ajax will be very helpful in making those things possible..