I was wondering if PHP can act as a server over a TCP port? How many IDLE connections can a 1GB RAM server handle? Can PHP receive many connections to one TCP port (like apache does on port 80?)
If i have a client connected to the socket opened by PHP, how can I send data to it? (for example a.php is listening on port 5000, some client is connected, later on b.php needs to send something to that client, well push a message?)
Or shall i use UDP instead?
Friend, my first advice is that even if PHP can do this natively. PHP is not the best technology to implement a TCP Sockets Server. The reason is because remember php
has max_execution_time for each script and make a server run forever will require set this value to 0 wich means forever. The amount of connections of 1gb of ram server can handle depends on how much ram and processor consume each php process.
But anyway, if you decide to do it using php. Yes, you can build with php an asynchronous tcp socket server.
Just create a master socket listening 5000(for example). And for each client sockets that connects with this master socket then create a child socket with a random free port(selected by the os) for each incoming connection and you can start talking with the child socket while releasing the master to continue listening for another incoming connections.