aximbigfan Posted September 19, 2008 Share Posted September 19, 2008 Hi, I have here the source code to a PHP socket server that is "multithreaded". The issue is that it will only accept up to $max_clients connections. Can anyone see any way to modify this so that it will accept more than $max_clients connections? <?php while (true) { $read[0] = $sock; for ($i = 0; $i < $max_clients; $i++) { if ($client[$i]['sock'] != null) $read[$i + 1] = $client[$i]['sock'] ; } $ready = socket_select($read,null,null,null); if (in_array($sock, $read)) { for ($i = 0; $i < $max_clients; $i++) { if ($client[$i]['sock'] == null) { $client[$i]['sock'] = socket_accept($sock); break; } elseif ($i == $max_clients - 1) echo "Client overflow error"; } if (--$ready <= 0) continue; } // If a client is trying to write - handle it now for ($i = 0; $i < $max_clients; $i++) // for each client { if (in_array($client[$i]['sock'] , $read)) { $input = socket_read($client[$i]['sock'] , 1024); //Stuff here } } else { // Close the socket socket_close($client[$i]['sock']); unset($client[$i]); } } } socket_close($sock); ?> Loops aren't my thing.. Thanks, Chris Quote Link to comment https://forums.phpfreaks.com/topic/124978-infinate-amounts-of-connections/ Share on other sites More sharing options...
Maq Posted September 19, 2008 Share Posted September 19, 2008 $max_clients = 1000000000; while (true) { Quote Link to comment https://forums.phpfreaks.com/topic/124978-infinate-amounts-of-connections/#findComment-645758 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.