@@ -40,7 +40,7 @@ public function start() {
4040 if ( $ client ) {
4141 echo "New client connected. \n" ;
4242 $ this ->clients [] = $ client ;
43- $ client_id = spl_object_id ( $ client );
43+ $ client_id = $ this -> get_client_id ( $ client );
4444 $ this ->client_servers [ $ client_id ] = new MySQL_Session ( $ this ->query_handler );
4545
4646 // Send initial handshake
@@ -75,7 +75,7 @@ public function start() {
7575 if ( false === $ data || '' === $ data ) {
7676 // Client disconnected
7777 echo "Client disconnected. \n" ;
78- $ client_id = spl_object_id ( $ client );
78+ $ client_id = $ this -> get_client_id ( $ client );
7979 $ this ->client_servers [ $ client_id ]->reset ();
8080 unset( $ this ->client_servers [ $ client_id ] );
8181 socket_close ( $ client );
@@ -85,7 +85,7 @@ public function start() {
8585
8686 try {
8787 // Process the data
88- $ client_id = spl_object_id ( $ client );
88+ $ client_id = $ this -> get_client_id ( $ client );
8989 echo "Receiving bytes \n" ;
9090 $ response = $ this ->client_servers [ $ client_id ]->receive_bytes ( $ data );
9191 if ( $ response ) {
@@ -116,4 +116,18 @@ public function start() {
116116 echo "restarting the while() loop! \n" ;
117117 }
118118 }
119+
120+ /**
121+ * Get a numeric ID for a client connected to the proxy.
122+ *
123+ * @param resource|object $client The client Socket object or resource.
124+ * @return int The numeric ID of the client.
125+ */
126+ private function get_client_id ( $ client ): int {
127+ if ( is_resource ( $ client ) ) {
128+ return get_resource_id ( $ client );
129+ } else {
130+ return spl_object_id ( $ client );
131+ }
132+ }
119133}
0 commit comments