A simple PHP socket server which doesn’t require process forking.
Comes with a few basic commands, feel free to use from GitHub.
Trawling through sold old project files, I came across a PHP socket server a wrote in 2014. I thought I’d post the code here if anyone was looking to work on a similar project. Source code on GitHub.
The script loops through all clients waiting for input to handle, clients can connect using a Telnet console. Defaults to listen on all interfaces over port 2014. This can be changed in the index.php by editing the following code:
Server::start( '0.0.0.0', 2014 );
It currently has the following commands available to connected clients:
broadcast ...
Sends a string to server, to be sent to all connect clients.echo ...
Sends a string to server to echo back.info
Returns server up time and a list of client connection details.quit
Closes the client connection.shutdown
Disconnects all clients and shuts down the server.time
Returns current server time.