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 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) { Link to comment https://forums.phpfreaks.com/topic/124978-infinate-amounts-of-connections/#findComment-645758 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.