tcp wrote in php

Hey everyone, I wrote a PHP program to accept incoming connections via telnet or any client program, but everytime I connect to the server running in the background (which the source is here ), the server program seems to close once a client disconnects. does anyone know how to fix this? I'm trying to create a chat program