$client1, "id" => $a); $a++; } // If a client is trying to write - handle it now foreach ($clients as $client) { $input = socket_read($client, 1024 * 1024); // Zero length string meaning disconnected if ($input == null) { $key = array_search($client, $clients); unset($clients[$key]); } $n = trim($input); if ($input) { socket_write($clients[$key], $ip); } } } // eo master loop // Close the master sockets socket_close($master_socket); function client_ip() { // true client ip if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet { return $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy { return $_SERVER['HTTP_X_FORWARDED_FOR']; } else { return $_SERVER['REMOTE_ADDR']; } }