PHP includes a network function called fsockopen, which creates a “file type” socket, allowing use of fgets and fputs on the socket stream. Using this method you can create small bots that sign in, do a small task and disconnect.
Start off by connecting to the server, then using a while loop with the condition of the resource not being EOF (i.e. the connection is still active). The code inside the while loop should be getting the data from the socket (line by line) and processing it, preferably passing it to another function. That function can then split the command into arguments separated by spaces and use a switch statement against the first argument in the array.
Here is a quick sample: