I'm trying to make my PHP server a bit more efficient.
I've built an object named Client
which contains the connected client (which has an open socket connection with the server) information such as name
, id
etc.
For now I have one array of socket connections, and one array of Client objects. When I'm referring a connection, I'm searching inside my Client array to find the right client who matches this connection. It works great, but it's a bit inefficient.. For small amount of clients in the server you don't feel it, but I'm afraid that if I'll have thousands of connection it will slow down the server.
As a solution I thought about 2 dimensional array, but I have a logic problem designing it.
Can I do something like this:
$clients = array();
$temp = array($newsock, new Client());
$clients[] = $temp;
I want my $clients[]
to be the socket and the $clients[][]
to be the client object.
In each row of $client
I will have only $client[$index][0]
which will be my client object for that connection.
Will I be able to send this to the socket_select()
function?