Jump to content

sockets stop connecting after 100 attempts


tehcrasx

Recommended Posts

Hey all,

I have a php application that connects to a server to get information but the server changes ports sometimes over a range. I need to be able to scan that range and find the port fairly quick. However after 100 checks php stops executing. Why is that?

code:

 

 

error_reporting(1);

$port=0;

$ip="192.168.1.66";

for($i=11100;$i<11999;$i++){

try{

$handle = socket_create(AF_INET,SOCK_DGRAM, SOL_UDP);

if (!@socket_connect($handle,$ip,$i)) {

throw new Exception( "$errno : $errstr <br/>");

}else{

socket_write($handle, "\\status\\");

if(!socket_read($handle, "2048")){

socket_close($handle);

socket_clear_error($handle);

throw new Exception("");}

$port=$i;

 

break;

}

}catch(Exception $e){

echo "not $i<br />";

echo $e->getMessage();

flush();

}

}

echo "<br />$port<br />";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.