It looks like you are limiting the overall polling connections to the server. The client can be informed by the server response.
To calculate the server connection without tapping into system variables or induce much expensive I/O, you can use a heuristic: Set up memcache and increase a counter each time you get a request. Set the timeout to, say, 5 seconds. This allows you to limit the total connections within the 5-second window.
The server response then tells the client either the total count, or a simple yes/no to whether it has more connections to spare. Your client program can react accordingly.
Edit:
installing memcached and memcache extension on Ubuntu:
apt-get install php5-memcache
apt-get install memcached
Here's the documentation on how to use the memcache API.
My original strategy with a single variable won't work. You can set up multiple keys, say, channel_0, channel_1, ..., channel_9, assuming there won't be too many channels because you're returning a video feed?
Then when a connection comes in, you look for a non-busy channel, and block that for a period of time:
$memcache_obj = memcache_connect('memcache_host', 11211);
$channel=null;
for ($i=0;$i<10;$i++){
if (memcache_get($memcache_obj,'channel_'.$channel)=='') {
$channel=$i;
memcache_set($memcache_obj, 'channel_'.$channel, '1', 0, 10); //block for 10 seconds
break;
}
}
if ($channel==null) // tell the client there's no more space